diff options
author | Andreas Gohr <andi@splitbrain.org> | 2023-09-02 14:42:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 14:42:51 +0200 |
commit | 5ff5424d8c81c7123d8656a787af2ff85b3dec21 (patch) | |
tree | 322929ee01d892bb3c927e7fe1238369c647f820 /inc/Parsing/Lexer | |
parent | 0613df3287b82a98b1e97cf86ed9d4c8fbd16f1c (diff) | |
parent | 91560755291852b8302767d454183a7662666f7e (diff) | |
download | dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.tar.gz dokuwiki-5ff5424d8c81c7123d8656a787af2ff85b3dec21.zip |
Merge pull request #4045 from dokuwiki/autofix
Use Rector to autofix code smell
Diffstat (limited to 'inc/Parsing/Lexer')
-rw-r--r-- | inc/Parsing/Lexer/Lexer.php | 28 | ||||
-rw-r--r-- | inc/Parsing/Lexer/ParallelRegex.php | 18 | ||||
-rw-r--r-- | inc/Parsing/Lexer/StateStack.php | 5 |
3 files changed, 25 insertions, 26 deletions
diff --git a/inc/Parsing/Lexer/Lexer.php b/inc/Parsing/Lexer/Lexer.php index 20040938e..168127138 100644 --- a/inc/Parsing/Lexer/Lexer.php +++ b/inc/Parsing/Lexer/Lexer.php @@ -1,4 +1,5 @@ <?php + /** * Lexer adapted from Simple Test: http://sourceforge.net/projects/simpletest/ * For an intro to the Lexer see: @@ -18,13 +19,13 @@ namespace dokuwiki\Parsing\Lexer; class Lexer { /** @var ParallelRegex[] */ - protected $regexes; + protected $regexes = []; /** @var \Doku_Handler */ protected $handler; /** @var StateStack */ protected $modeStack; /** @var array mode "rewrites" */ - protected $mode_handlers; + protected $mode_handlers = []; /** @var bool case sensitive? */ protected $case; @@ -38,10 +39,8 @@ class Lexer public function __construct($handler, $start = "accept", $case = false) { $this->case = $case; - $this->regexes = array(); $this->handler = $handler; $this->modeStack = new StateStack($start); - $this->mode_handlers = array(); } /** @@ -141,13 +140,13 @@ class Lexer $length = $initialLength; $pos = 0; while (is_array($parsed = $this->reduce($raw))) { - list($unmatched, $matched, $mode) = $parsed; + [$unmatched, $matched, $mode] = $parsed; $currentLength = strlen($raw); $matchPos = $initialLength - $currentLength - strlen($matched); if (! $this->dispatchTokens($unmatched, $matched, $mode, $pos, $matchPos)) { return false; } - if ($currentLength == $length) { + if ($currentLength === $length) { return false; } $length = $currentLength; @@ -265,8 +264,8 @@ class Lexer // modes starting with plugin_ are all handled by the same // handler but with an additional parameter - if (substr($handler, 0, 7)=='plugin_') { - list($handler,$plugin) = sexplode('_', $handler, 2, ''); + if (substr($handler, 0, 7) == 'plugin_') { + [$handler, $plugin] = sexplode('_', $handler, 2, ''); return $this->handler->$handler($content, $is_match, $pos, $plugin); } @@ -291,8 +290,8 @@ class Lexer return true; } if ($action = $this->regexes[$this->modeStack->getCurrent()]->split($raw, $split)) { - list($unparsed, $match, $raw) = $split; - return array($unparsed, $match, $action); + [$unparsed, $match, $raw] = $split; + return [$unparsed, $match, $action]; } return true; } @@ -305,7 +304,7 @@ class Lexer */ public static function escape($str) { - $chars = array( + $chars = [ '/\\\\/', '/\./', '/\+/', @@ -323,9 +322,9 @@ class Lexer '/\>/', '/\|/', '/\:/' - ); + ]; - $escaped = array( + $escaped = [ '\\\\\\\\', '\.', '\+', @@ -343,7 +342,8 @@ class Lexer '\>', '\|', '\:' - ); + ]; + return preg_replace($chars, $escaped, $str); } } diff --git a/inc/Parsing/Lexer/ParallelRegex.php b/inc/Parsing/Lexer/ParallelRegex.php index bf1979950..d23fb332b 100644 --- a/inc/Parsing/Lexer/ParallelRegex.php +++ b/inc/Parsing/Lexer/ParallelRegex.php @@ -1,4 +1,5 @@ <?php + /** * Lexer adapted from Simple Test: http://sourceforge.net/projects/simpletest/ * For an intro to the Lexer see: @@ -17,9 +18,9 @@ namespace dokuwiki\Parsing\Lexer; class ParallelRegex { /** @var string[] patterns to match */ - protected $patterns; + protected $patterns = []; /** @var string[] labels for above patterns */ - protected $labels; + protected $labels = []; /** @var string the compound regex matching all patterns */ protected $regex; /** @var bool case sensitive matching? */ @@ -34,9 +35,6 @@ class ParallelRegex public function __construct($case) { $this->case = $case; - $this->patterns = array(); - $this->labels = array(); - $this->regex = null; } /** @@ -121,15 +119,15 @@ class ParallelRegex } } - $split = array($subject, "", ""); + $split = [$subject, "", ""]; return false; } - $idx = count($matches)-2; - list($pre, $post) = preg_split($this->patterns[$idx].$this->getPerlMatchingFlags(), $subject, 2); - $split = array($pre, $matches[0], $post); + $idx = count($matches) - 2; + [$pre, $post] = preg_split($this->patterns[$idx] . $this->getPerlMatchingFlags(), $subject, 2); + $split = [$pre, $matches[0], $post]; - return isset($this->labels[$idx]) ? $this->labels[$idx] : true; + return $this->labels[$idx] ?? true; } /** diff --git a/inc/Parsing/Lexer/StateStack.php b/inc/Parsing/Lexer/StateStack.php index 325412bb4..a2d72e487 100644 --- a/inc/Parsing/Lexer/StateStack.php +++ b/inc/Parsing/Lexer/StateStack.php @@ -1,4 +1,5 @@ <?php + /** * Lexer adapted from Simple Test: http://sourceforge.net/projects/simpletest/ * For an intro to the Lexer see: @@ -22,7 +23,7 @@ class StateStack */ public function __construct($start) { - $this->stack = array($start); + $this->stack = [$start]; } /** @@ -41,7 +42,7 @@ class StateStack */ public function enter($state) { - array_push($this->stack, $state); + $this->stack[] = $state; } /** |