public function validate($element): bool
    {
        if (!$expectedType = $this->getType()) {
            return true;
        }

        $expectedType = $this->typeMap[$expectedType] ?? $expectedType;
        $actualType   = \gettype($element);

        if (($actualType === 'object' && $element instanceof $expectedType) || $actualType === $expectedType) {
            return true;
        }

        throw new InvalidTypeException($expectedType, $actualType === 'object' ? \get_class($element) : $actualType);
    }
public function validate($element): bool
    {
        if (!$expectedType = $this->getType()) {
            return true;
        }

        $expectedType = $this->typeMap[$expectedType] ?? $expectedType;
        $actualType   = \gettype($element);

        if (($actualType === 'object' && $element instanceof $expectedType) || $actualType === $expectedType) {
            return true;
        }

        throw new InvalidTypeException($expectedType, $actualType === 'object' ? \get_class($element) : $actualType);
    }
public function validate ( $ element ) : bool { if ( ! $ expectedType = $ this -> getType ( ) ) { return true ; } $ expectedType = $ this -> typeMap [ $ expectedType ] ?? $ expectedType ; $ actualType = \ gettype ( $ element ) ; if ( ( $ actualType === 'object' && $ element instanceof $ expectedType ) || $ actualType === $ expectedType ) { return true ; } throw new InvalidTypeException ( $ expectedType , $ actualType === 'object' ? \ get_class ( $ element ) : $ actualType ) ; }
Returns whether the given element is a valid type.

@param mixed $element

@return bool

@throws InvalidTypeException
Returns whether the given element is a valid type .