Accepts the next token if it's of given type and optionally has given value

@param int $type
@param null $value
@return bool
17158
public function acceptNext(int $type, $value = null) : bool
    {
        if ($this->getNextToken()->getType() === $type) {
            if ($value) {
                if ($this->getNextToken()->getValue() === $value) {
                    return true;
                }

                return false;
            }

            return true;
        }

        return false;
    }
364639
public static function decodeFromBase64(string $value, string $type = null)
    {
        return self::run(self::DECODER, \base64_decode($value), $type);
    }
413630
public function acceptToken($type, &$token = null)
    {
        $token = $this->peek();
        if (! isset($token[0]) or $token[0] != $type) {
            return false;
        }
        $this->pop();
        return true;
    }
971541
public static function with(string $type, string $value): self
    {
        $targetType = strtolower($type);

        $new = new self();
        $new->type = $targetType;

        switch ($targetType) {
            case self::CONDITION:
                $new->value = (string) Condition::fromValue($value);
                break;
            case self::TOKEN:
                $new->value = (string) RegistrationToken::fromValue($value);
                break;
            case self::TOPIC:
                $new->value = (string) Topic::fromValue($value);
                break;
            default:
                throw new InvalidArgumentException('Invalid target type "'.$type.'", valid type: "'.implode(', ', self::TYPES));
        }

        return $new;
    }
153682
protected function toNull($value)
    {
        if ($value === 0 || $value === false || $value === '') {
            return null;
        }
        if ($this->getTypeCheck()->isArray($value) && count($value) === 1) {
            return $this->toNull(reset($value));
        }

        return $value;
    }
1230667
public function param($param, $value, $type = null)
    {
        return $this->setParameter($param, $value, $type);
    }
1090729
private function isType(string $type, $value): bool
    {
        switch ($type) {
            case 'int':
                return is_int($value);
            case 'float':
                return is_float($value);
            case 'bool':
                return is_bool($value);
            case 'string':
                return is_string($value);
            case 'array':
                return is_array($value);
            case 'object':
                return is_object($value);
            case 'resource':
                return is_resource($value);
            case 'callable':
                return is_callable($value);
            case 'mixed':
                return true;
            default:
                return $value instanceof $type;
        }
    }
1080940
private function parserParamType(string $type, $value)
    {
        switch ($type) {
            case 'int':
                $value = (int)$value;
                break;
            case 'string':
                $value = (string)$value;
                break;
            case 'bool':
                $value = (bool)$value;
                break;
            case 'float':
                $value = (float)$value;
                break;
            case 'double':
                $value = (double)$value;
                break;
        }

        return $value;
    }
1111855
public static function addHeader($type, $value, $code = null) {

		if(false == is_string($type)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
		}

		if(false == is_string($value) && false == is_numeric($value)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($value)), E_USER_ERROR);
		}

		if(null !== $code && false === ('-' . intval($code) == '-' . $code)) {
			return trigger_error(sprintf('Argument 3 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($code)), E_USER_ERROR);
		}

		if(null === $code) {
			return header($type . ':' . $value, true);
		}

		header($type . ':' . $value, true, $code);
	}
1013447
protected function validate_version( $value, $type = '' ) {
		if ( false === $value || empty( $value ) || is_null( $value ) ) {
			return false;
		}

		if ( 'option' === $type ) {
			return version_compare( $this->option_version, $value, '=' );
		}

		return version_compare( $this->transient_version, $value, '=' );
	}
998198
public static function setType($value, $type, $nullable = TRUE)
	{
		if (!$nullable || NULL !== $value) {
			settype($value, $type);
		}

		return $value;
	}
317787
public static function factory($type = null, $text = null, $length = null, $value = null)
    {
        $token = new static();
        if (null !== $type) {
            $token->setType($type);
        }
        if (null !== $text) {
            $token->setText($text);
        }
        if (null !== $length) {
            $token->setLength($length);
        }
        if (null !== $value) {
            $token->setValue($value);
        }
        return $token;
    }
324092
protected function toType($value, $type)
    {
        if (in_array($type, ['integer', 'float']) && !in_array($value, ['', null], true)) {
            settype($value, $type);
        } else if ($type == 'boolean') {
            $value = (bool)$value;
        } else if ($type == 'many') {
            $value = $value ?: [];
        }
        return $value === '' ? null : $value;
    }
855753
public function match($type, $value = null)
    {
        if ($this->type === $type || (is_array($type) && in_array($this->type, $type))) {
            if (null === $value || $this->value == $value || (is_array($value) && in_array($this->value, $value))) {
                return true;
            }
        }
        return false;
    }
1018801
public function bind($param, $value, $type = null)
    {
        if (is_null($type)) {
            switch (true) {
                case is_int($value):
                    $type = PDO::PARAM_INT;
                    break;
                case is_bool($value):
                    $type = PDO::PARAM_BOOL;
                    break;
                case is_null($value):
                    $type = PDO::PARAM_NULL;
                    break;
                default:
                    $type = PDO::PARAM_STR;
            }
        }
        //then run PDO bindValue on the statement to bind the values
        self::$statement->bindValue($param, $value, $type);
    }
1178702
public static function fixType($value, $type = \PDO::PARAM_STR)
    {
        if ($value === null) {
            return null;
        }

        switch ($type) {
            case \PDO::PARAM_NULL:
                return null;
            case \PDO::PARAM_INT:
                $float = floatval($value);
                $int = intval($float);
                if ($float && $int != $float) {
                    return $float;
                }

                return $int;
            case \PDO::PARAM_BOOL:
                return $value ? 1 : 0;
        }

        return $value;
    }
987414
protected function assertTypeEquals(string $type, $value): bool
    {
        if (\strpos($type, '[]') !== false) {
            return $this->isValidGenericCollection($type, $value);
        }

        if ($type === 'mixed' && $value !== null) {
            return true;
        }

        return $value instanceof $type
               ||
               \gettype($value) === (self::$typeMapping[$type] ?? $type);
    }