src/Parser/Parser.php
/**
     * Try parse an assert.
     *
     * @param LocationInterface    $location    The location.
     * @param string               $command     The command.
     * @param string|null          $argument    The argument or null if no argument.
     * @param array                $parseErrors The parse errors.
     * @param AssertInterface|null $assert      The parses assert or null if parsing failed.
     *
     * @return bool True if this was an assert, false otherwise.
     */
Try parse an assert.
@param LocationInterface    $location    The location.
@param string               $command     The command.
@param string|null          $argument    The argument or null if no argument.
@param array                $parseErrors The parse errors.
@param AssertInterface|null $assert      The parses assert or null if parsing failed.

@return bool True if this was an assert, false otherwise.
Try parse an assert . @param LocationInterface $location The location . @param string $command The command . @param string|null $argument The argument or null if no argument . @param array $parseErrors The parse errors . @param AssertInterface|null $assert The parses assert or null if parsing failed . @return bool True if this was an assert false otherwise .
private static function tryParseAssert(LocationInterface $location, string $command, ?string $argument, array &$parseErrors, ?AssertInterface &$assert): bool
    {
        $assert = null;
        self::extractModifiers($command, $assertString, $modifiersString);
        if (!isset(self::ASSERTS_INFO[$assertString])) {
            return false;
        }
        $assertInfo = self::ASSERTS_INFO[$assertString];
        $className = $assertInfo[0];
        $argumentType = $assertInfo[1];
        $argumentName = $assertInfo[2];
        $argumentResult = self::checkAssertArgument($argument, $argumentType, $argumentValue);
        if ($argumentResult !== self::ARGUMENT_OK) {
            switch ($argumentResult) {
                case self::ARGUMENT_ERROR_EXTRA_ARGUMENT:
                    $parseErrors[] = new ParseError($location, 'Extra argument: "' . $argument . '". No arguments are allowed for assert "' . $command . '".');
                    break;
                case self::ARGUMENT_ERROR_MISSING_ARGUMENT:
                    $parseErrors[] = new ParseError($location, 'Missing argument: Missing ' . $argumentName . ' argument for assert "' . $command . '".');
                    break;
                case self::ARGUMENT_ERROR_INVALID_ARGUMENT_TYPE:
                    $parseErrors[] = new ParseError($location, 'Invalid argument: ' . ucfirst($argumentName) . ' "' . $argument . '" must be of type ' . $argumentType . ' for assert "' . $command . '".');
                    break;
            }
            return true;
        }
        self::tryParseModifiers($location, $assertString, $modifiersString, $parseErrors, $modifiers);
        if ($modifiers === null) {
            return true;
        }
        try {
            $assert = $argumentValue === null ?
                new $className($location, $modifiers) :
                new $className($location, $argumentValue, $modifiers);
        } catch (InvalidParameterException $e) {
            $parseErrors[] = new ParseError($location, 'Invalid argument: ' . $e->getMessage() . ' for assert "' . $command . '".');
        } catch (NotAllowedModifierException $e) {
            $invalidModifiers = [];
            foreach (self::MODIFIERS_INFO as $char => $value) {
                if ($e->getModifiers()->contains(new Modifiers($value))) {
                    $invalidModifiers[] = '"' . $char . '"';
                }
            }
            $isMultiple = count($invalidModifiers) > 1;
            $parseErrors[] = new ParseError($location, 'Invalid modifier' . ($isMultiple ? 's' : '') . ': Modifier' . ($isMultiple ? 's' : '') . ' ' . implode(', ', $invalidModifiers) . ' ' . ($isMultiple ? 'are' : 'is') . ' not allowed for assert "' . $assertString . '".');
        }
        return true;
    }
private static function tryParseAssert ( LocationInterface $ location , string $ command , ? string $ argument , array & $ parseErrors , ? AssertInterface & $ assert ) : bool { $ assert = null ; self :: extractModifiers ( $ command , $ assertString , $ modifiersString ) ; if ( ! isset ( self :: ASSERTS_INFO [ $ assertString ] ) ) { return false ; } $ assertInfo = self :: ASSERTS_INFO [ $ assertString ] ; $ className = $ assertInfo [ 0 ] ; $ argumentType = $ assertInfo [ 1 ] ; $ argumentName = $ assertInfo [ 2 ] ; $ argumentResult = self :: checkAssertArgument ( $ argument , $ argumentType , $ argumentValue ) ; if ( $ argumentResult !== self :: ARGUMENT_OK ) { switch ( $ argumentResult ) { case self :: ARGUMENT_ERROR_EXTRA_ARGUMENT : $ parseErrors [ ] = new ParseError ( $ location , 'Extra argument: "' . $ argument . '". No arguments are allowed for assert "' . $ command . '".' ) ; break ; case self :: ARGUMENT_ERROR_MISSING_ARGUMENT : $ parseErrors [ ] = new ParseError ( $ location , 'Missing argument: Missing ' . $ argumentName . ' argument for assert "' . $ command . '".' ) ; break ; case self :: ARGUMENT_ERROR_INVALID_ARGUMENT_TYPE : $ parseErrors [ ] = new ParseError ( $ location , 'Invalid argument: ' . ucfirst ( $ argumentName ) . ' "' . $ argument . '" must be of type ' . $ argumentType . ' for assert "' . $ command . '".' ) ; break ; } return true ; } self :: tryParseModifiers ( $ location , $ assertString , $ modifiersString , $ parseErrors , $ modifiers ) ; if ( $ modifiers === null ) { return true ; } try { $ assert = $ argumentValue === null ? new $ className ( $ location , $ modifiers ) : new $ className ( $ location , $ argumentValue , $ modifiers ) ; } catch ( InvalidParameterException $ e ) { $ parseErrors [ ] = new ParseError ( $ location , 'Invalid argument: ' . $ e -> getMessage ( ) . ' for assert "' . $ command . '".' ) ; } catch ( NotAllowedModifierException $ e ) { $ invalidModifiers = [ ] ; foreach ( self :: MODIFIERS_INFO as $ char => $ value ) { if ( $ e -> getModifiers ( ) -> contains ( new Modifiers ( $ value ) ) ) { $ invalidModifiers [ ] = '"' . $ char . '"' ; } } $ isMultiple = count ( $ invalidModifiers ) > 1 ; $ parseErrors [ ] = new ParseError ( $ location , 'Invalid modifier' . ( $ isMultiple ? 's' : '' ) . ': Modifier' . ( $ isMultiple ? 's' : '' ) . ' ' . implode ( ', ' , $ invalidModifiers ) . ' ' . ( $ isMultiple ? 'are' : 'is' ) . ' not allowed for assert "' . $ assertString . '".' ) ; } return true ; }
Try parse an assert.
Try parse an assert .