src/Parser/Parser.php
/**
     * Try parse a set command.
     *
     * @param LocationInterface     $location     The location.
     * @param string                $command      The command.
     * @param string|null           $argument     The argument or null if no argument.
     * @param ParseContextInterface $parseContext The parse context.
     * @param ParseErrorInterface[] $parseErrors  The parse errors.
     *
     * @return bool
     */
Try parse a set command.
@param LocationInterface     $location     The location.
@param string                $command      The command.
@param string|null           $argument     The argument or null if no argument.
@param ParseContextInterface $parseContext The parse context.
@param ParseErrorInterface[] $parseErrors  The parse errors.

@return bool
Try parse a set command . @param LocationInterface $location The location . @param string $command The command . @param string|null $argument The argument or null if no argument . @param ParseContextInterface $parseContext The parse context . @param ParseErrorInterface [] $parseErrors The parse errors . @return bool
private static function tryParseSet(LocationInterface $location, string $command, ?string $argument, ParseContextInterface $parseContext, array &$parseErrors): bool
    {
        switch ($command) {
            case 'set':
                $isDefaultSet = false;
                break;
            case 'set-default':
                $isDefaultSet = true;
                break;
            default:
                return false;
        }
        if ($argument === null) {
            $parseErrors[] = new ParseError($location, 'Missing variable: Missing variable name and value for "' . $command . '".');
            return true;
        }
        $argumentParts = explode('=', $argument, 2);
        $variableName = trim($argumentParts[0]);
        if ($variableName === '') {
            $parseErrors[] = new ParseError($location, 'Missing variable: Missing variable name for "' . $command . '" in "' . $argument . '".');
            return true;
        }
        if (!self::isValidVariableName($variableName)) {
            $parseErrors[] = new ParseError($location, 'Invalid variable: Invalid variable name "' . $variableName . '" for "' . $command . '" in "' . $argument . '".');
            return true;
        }
        $variableValue = count($argumentParts) > 1 ? trim($argumentParts[1]) : null;
        if ($variableValue === null) {
            $parseErrors[] = new ParseError($location, 'Missing variable: Missing variable value for "' . $command . '" in "' . $argument . '".');
            return true;
        }
        if ($isDefaultSet && $parseContext->hasVariable($variableName)) {
            return true;
        }
        $parseContext->setVariable($variableName, $variableValue);
        return true;
    }
private static function tryParseSet ( LocationInterface $ location , string $ command , ? string $ argument , ParseContextInterface $ parseContext , array & $ parseErrors ) : bool { switch ( $ command ) { case 'set' : $ isDefaultSet = false ; break ; case 'set-default' : $ isDefaultSet = true ; break ; default : return false ; } if ( $ argument === null ) { $ parseErrors [ ] = new ParseError ( $ location , 'Missing variable: Missing variable name and value for "' . $ command . '".' ) ; return true ; } $ argumentParts = explode ( '=' , $ argument , 2 ) ; $ variableName = trim ( $ argumentParts [ 0 ] ) ; if ( $ variableName === '' ) { $ parseErrors [ ] = new ParseError ( $ location , 'Missing variable: Missing variable name for "' . $ command . '" in "' . $ argument . '".' ) ; return true ; } if ( ! self :: isValidVariableName ( $ variableName ) ) { $ parseErrors [ ] = new ParseError ( $ location , 'Invalid variable: Invalid variable name "' . $ variableName . '" for "' . $ command . '" in "' . $ argument . '".' ) ; return true ; } $ variableValue = count ( $ argumentParts ) > 1 ? trim ( $ argumentParts [ 1 ] ) : null ; if ( $ variableValue === null ) { $ parseErrors [ ] = new ParseError ( $ location , 'Missing variable: Missing variable value for "' . $ command . '" in "' . $ argument . '".' ) ; return true ; } if ( $ isDefaultSet && $ parseContext -> hasVariable ( $ variableName ) ) { return true ; } $ parseContext -> setVariable ( $ variableName , $ variableValue ) ; return true ; }
Try parse a set command.
Try parse a set command .