diff options
Diffstat (limited to 'src/Components/OptionsArray.php')
-rw-r--r-- | src/Components/OptionsArray.php | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index 69aabb3..da73dc6 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -1,8 +1,8 @@ <?php - /** * Parses a list of options. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Translator; /** * Parses a list of options. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptionsArray extends Component { @@ -26,16 +22,14 @@ class OptionsArray extends Component * * @var array */ - public $options = array(); + public $options = []; /** - * Constructor. - * * @param array $options The array of options. Options that have a value * must be an array with at least two keys `name` and * `expr` or `value`. */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { $this->options = $options; } @@ -47,9 +41,9 @@ class OptionsArray extends Component * * @return OptionsArray */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The ID that will be assigned to duplicate options. @@ -167,7 +161,7 @@ class OptionsArray extends Component // This is only the beginning. The value is parsed in state // 1 and 2. State 1 is used to skip the first equals sign // and state 2 to parse the actual value. - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. @@ -176,8 +170,8 @@ class OptionsArray extends Component // @var string Raw value. 'expr' => '', // @var string Processed value. - 'value' => '' - ); + 'value' => '', + ]; $state = 1; } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { // This is a keyword that is followed by an expression. @@ -185,15 +179,15 @@ class OptionsArray extends Component // Skipping this option in order to parse the expression. ++$list->idx; - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. // This is used by the builder to rebuild it. 'equals' => $lastOption[1] === 'expr=', // @var Expression The parsed expression. - 'expr' => '' - ); + 'expr' => '', + ]; $state = 1; } } elseif ($state === 1) { @@ -211,7 +205,7 @@ class OptionsArray extends Component $ret->options[$lastOptionId]['expr'] = Expression::parse( $parser, $list, - empty($lastOption[2]) ? array() : $lastOption[2] + empty($lastOption[2]) ? [] : $lastOption[2] ); $ret->options[$lastOptionId]['value'] = $ret->options[$lastOptionId]['expr']->expr; @@ -276,19 +270,19 @@ class OptionsArray extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (empty($component->options)) { return ''; } - $options = array(); + $options = []; foreach ($component->options as $option) { if (! is_array($option)) { $options[] = $option; } else { $options[] = $option['name'] - . ((! empty($option['equals']) && $option['equals']) ? '=' : ' ') + . (! empty($option['equals']) && $option['equals'] ? '=' : ' ') . (! empty($option['expr']) ? $option['expr'] : $option['value']); } } |