QuackCompiler\Types\Type::getBaseType PHP Method

getBaseType() public static method

public static getBaseType ( $types )
    public static function getBaseType($types)
    {
        if (0 === sizeof($types)) {
            return null;
        }
        // Currently, implemented only for numbers
        if ($types[0]->isNumber()) {
            return new Type(max(array_map(function ($type) {
                return $type->code;
            }, $types)));
        }
        // No base type. Let's clone the initial type
        return clone $types[0];
    }

Usage Example

Beispiel #1
0
 public function getType()
 {
     $newtype = new Type(NativeQuackType::T_LIST);
     $type = (object) ['from' => $this->from->getType(), 'to' => $this->to->getType(), 'by' => null !== $this->by ? $this->by->getType() : null];
     $throw_error_on = function ($operand, $got) {
         throw new ScopeError(['message' => "Expected number on operand `{$operand}' of range expression. Got {$got}"]);
     };
     if (!$type->from->isNumber()) {
         $throw_error_on('from', $type->from);
     }
     if (!$type->to->isNumber()) {
         $throw_error_on('to', $type->to);
     }
     if (null !== $type->by && !$type->by->isNumber()) {
         $throw_error_on('by', $type->by);
     }
     $newtype->subtype = Type::getBaseType(array_filter(array_values((array) $type), function ($t) {
         return null !== $t;
     }));
     return $newtype;
 }
All Usage Examples Of QuackCompiler\Types\Type::getBaseType