@@ -9,51 +9,51 @@ |
||
9 | 9 | |
10 | 10 | class Escaper |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array Characters to escape in a character class |
|
14 | - */ |
|
15 | - public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]']; |
|
12 | + /** |
|
13 | + * @var array Characters to escape in a character class |
|
14 | + */ |
|
15 | + public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]']; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array Characters to escape outside of a character class |
|
19 | - */ |
|
20 | - public $inLiteral = [ |
|
21 | - '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | - '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
23 | - '\\' => '\\\\', '^' => '\\^', '{' => '\\{', '|' => '\\|' |
|
24 | - ]; |
|
17 | + /** |
|
18 | + * @var array Characters to escape outside of a character class |
|
19 | + */ |
|
20 | + public $inLiteral = [ |
|
21 | + '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | + '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
23 | + '\\' => '\\\\', '^' => '\\^', '{' => '\\{', '|' => '\\|' |
|
24 | + ]; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string $delimiter Delimiter used in the final regexp |
|
28 | - */ |
|
29 | - public function __construct($delimiter = '/') |
|
30 | - { |
|
31 | - foreach (str_split($delimiter, 1) as $char) |
|
32 | - { |
|
33 | - $this->inCharacterClass[$char] = '\\' . $char; |
|
34 | - $this->inLiteral[$char] = '\\' . $char; |
|
35 | - } |
|
36 | - } |
|
26 | + /** |
|
27 | + * @param string $delimiter Delimiter used in the final regexp |
|
28 | + */ |
|
29 | + public function __construct($delimiter = '/') |
|
30 | + { |
|
31 | + foreach (str_split($delimiter, 1) as $char) |
|
32 | + { |
|
33 | + $this->inCharacterClass[$char] = '\\' . $char; |
|
34 | + $this->inLiteral[$char] = '\\' . $char; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Escape given character to be used in a character class |
|
40 | - * |
|
41 | - * @param string $char Original character |
|
42 | - * @return string Escaped character |
|
43 | - */ |
|
44 | - public function escapeCharacterClass($char) |
|
45 | - { |
|
46 | - return (isset($this->inCharacterClass[$char])) ? $this->inCharacterClass[$char] : $char; |
|
47 | - } |
|
38 | + /** |
|
39 | + * Escape given character to be used in a character class |
|
40 | + * |
|
41 | + * @param string $char Original character |
|
42 | + * @return string Escaped character |
|
43 | + */ |
|
44 | + public function escapeCharacterClass($char) |
|
45 | + { |
|
46 | + return (isset($this->inCharacterClass[$char])) ? $this->inCharacterClass[$char] : $char; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Escape given character to be used outside of a character class |
|
51 | - * |
|
52 | - * @param string $char Original character |
|
53 | - * @return string Escaped character |
|
54 | - */ |
|
55 | - public function escapeLiteral($char) |
|
56 | - { |
|
57 | - return (isset($this->inLiteral[$char])) ? $this->inLiteral[$char] : $char; |
|
58 | - } |
|
49 | + /** |
|
50 | + * Escape given character to be used outside of a character class |
|
51 | + * |
|
52 | + * @param string $char Original character |
|
53 | + * @return string Escaped character |
|
54 | + */ |
|
55 | + public function escapeLiteral($char) |
|
56 | + { |
|
57 | + return (isset($this->inLiteral[$char])) ? $this->inLiteral[$char] : $char; |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -9,38 +9,38 @@ |
||
9 | 9 | |
10 | 10 | class PromoteSingleStrings extends AbstractPass |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function processStrings(array $strings) |
|
16 | - { |
|
17 | - return array_map([$this, 'promoteSingleStrings'], $strings); |
|
18 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function processStrings(array $strings) |
|
16 | + { |
|
17 | + return array_map([$this, 'promoteSingleStrings'], $strings); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * Promote single strings found inside given string |
|
22 | - * |
|
23 | - * @param array $string Original string |
|
24 | - * @return array Modified string |
|
25 | - */ |
|
26 | - protected function promoteSingleStrings(array $string) |
|
27 | - { |
|
28 | - $newString = []; |
|
29 | - foreach ($string as $element) |
|
30 | - { |
|
31 | - if (is_array($element) && count($element) === 1) |
|
32 | - { |
|
33 | - foreach ($element[0] as $element) |
|
34 | - { |
|
35 | - $newString[] = $element; |
|
36 | - } |
|
37 | - } |
|
38 | - else |
|
39 | - { |
|
40 | - $newString[] = $element; |
|
41 | - } |
|
42 | - } |
|
20 | + /** |
|
21 | + * Promote single strings found inside given string |
|
22 | + * |
|
23 | + * @param array $string Original string |
|
24 | + * @return array Modified string |
|
25 | + */ |
|
26 | + protected function promoteSingleStrings(array $string) |
|
27 | + { |
|
28 | + $newString = []; |
|
29 | + foreach ($string as $element) |
|
30 | + { |
|
31 | + if (is_array($element) && count($element) === 1) |
|
32 | + { |
|
33 | + foreach ($element[0] as $element) |
|
34 | + { |
|
35 | + $newString[] = $element; |
|
36 | + } |
|
37 | + } |
|
38 | + else |
|
39 | + { |
|
40 | + $newString[] = $element; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - return $newString; |
|
45 | - } |
|
44 | + return $newString; |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -9,93 +9,93 @@ |
||
9 | 9 | |
10 | 10 | class MergePrefix extends AbstractPass |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function processStrings(array $strings) |
|
16 | - { |
|
17 | - $newStrings = []; |
|
18 | - foreach ($this->getStringsByPrefix($strings) as $prefix => $strings) |
|
19 | - { |
|
20 | - $newStrings[] = (isset($strings[1])) ? $this->mergeStrings($strings) : $strings[0]; |
|
21 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function processStrings(array $strings) |
|
16 | + { |
|
17 | + $newStrings = []; |
|
18 | + foreach ($this->getStringsByPrefix($strings) as $prefix => $strings) |
|
19 | + { |
|
20 | + $newStrings[] = (isset($strings[1])) ? $this->mergeStrings($strings) : $strings[0]; |
|
21 | + } |
|
22 | 22 | |
23 | - return $newStrings; |
|
24 | - } |
|
23 | + return $newStrings; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get the number of leading elements common to all given strings |
|
28 | - * |
|
29 | - * @param array[] $strings |
|
30 | - * @return integer |
|
31 | - */ |
|
32 | - protected function getPrefixLength(array $strings) |
|
33 | - { |
|
34 | - $len = 1; |
|
35 | - $cnt = count($strings[0]); |
|
36 | - while ($len < $cnt && $this->stringsMatch($strings, $len)) |
|
37 | - { |
|
38 | - ++$len; |
|
39 | - } |
|
26 | + /** |
|
27 | + * Get the number of leading elements common to all given strings |
|
28 | + * |
|
29 | + * @param array[] $strings |
|
30 | + * @return integer |
|
31 | + */ |
|
32 | + protected function getPrefixLength(array $strings) |
|
33 | + { |
|
34 | + $len = 1; |
|
35 | + $cnt = count($strings[0]); |
|
36 | + while ($len < $cnt && $this->stringsMatch($strings, $len)) |
|
37 | + { |
|
38 | + ++$len; |
|
39 | + } |
|
40 | 40 | |
41 | - return $len; |
|
42 | - } |
|
41 | + return $len; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Return given strings grouped by their first element |
|
46 | - * |
|
47 | - * NOTE: assumes that this pass is run before the first element of any string could be replaced |
|
48 | - * |
|
49 | - * @param array[] $strings |
|
50 | - * @return array[] |
|
51 | - */ |
|
52 | - protected function getStringsByPrefix(array $strings) |
|
53 | - { |
|
54 | - $byPrefix = []; |
|
55 | - foreach ($strings as $string) |
|
56 | - { |
|
57 | - $byPrefix[$string[0]][] = $string; |
|
58 | - } |
|
44 | + /** |
|
45 | + * Return given strings grouped by their first element |
|
46 | + * |
|
47 | + * NOTE: assumes that this pass is run before the first element of any string could be replaced |
|
48 | + * |
|
49 | + * @param array[] $strings |
|
50 | + * @return array[] |
|
51 | + */ |
|
52 | + protected function getStringsByPrefix(array $strings) |
|
53 | + { |
|
54 | + $byPrefix = []; |
|
55 | + foreach ($strings as $string) |
|
56 | + { |
|
57 | + $byPrefix[$string[0]][] = $string; |
|
58 | + } |
|
59 | 59 | |
60 | - return $byPrefix; |
|
61 | - } |
|
60 | + return $byPrefix; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Merge given strings into a new single string |
|
65 | - * |
|
66 | - * @param array[] $strings |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - protected function mergeStrings(array $strings) |
|
70 | - { |
|
71 | - $len = $this->getPrefixLength($strings); |
|
72 | - $newString = array_slice($strings[0], 0, $len); |
|
73 | - foreach ($strings as $string) |
|
74 | - { |
|
75 | - $newString[$len][] = array_slice($string, $len); |
|
76 | - } |
|
63 | + /** |
|
64 | + * Merge given strings into a new single string |
|
65 | + * |
|
66 | + * @param array[] $strings |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + protected function mergeStrings(array $strings) |
|
70 | + { |
|
71 | + $len = $this->getPrefixLength($strings); |
|
72 | + $newString = array_slice($strings[0], 0, $len); |
|
73 | + foreach ($strings as $string) |
|
74 | + { |
|
75 | + $newString[$len][] = array_slice($string, $len); |
|
76 | + } |
|
77 | 77 | |
78 | - return $newString; |
|
79 | - } |
|
78 | + return $newString; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Test whether all given strings' elements match at given position |
|
83 | - * |
|
84 | - * @param array[] $strings |
|
85 | - * @param integer $pos |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - protected function stringsMatch(array $strings, $pos) |
|
89 | - { |
|
90 | - $value = $strings[0][$pos]; |
|
91 | - foreach ($strings as $string) |
|
92 | - { |
|
93 | - if (!isset($string[$pos]) || $string[$pos] !== $value) |
|
94 | - { |
|
95 | - return false; |
|
96 | - } |
|
97 | - } |
|
81 | + /** |
|
82 | + * Test whether all given strings' elements match at given position |
|
83 | + * |
|
84 | + * @param array[] $strings |
|
85 | + * @param integer $pos |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + protected function stringsMatch(array $strings, $pos) |
|
89 | + { |
|
90 | + $value = $strings[0][$pos]; |
|
91 | + foreach ($strings as $string) |
|
92 | + { |
|
93 | + if (!isset($string[$pos]) || $string[$pos] !== $value) |
|
94 | + { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - return true; |
|
100 | - } |
|
99 | + return true; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | \ No newline at end of file |
@@ -9,40 +9,40 @@ |
||
9 | 9 | |
10 | 10 | class GroupSingleCharacters extends AbstractPass |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function processStrings(array $strings) |
|
16 | - { |
|
17 | - $singles = $this->getSingleCharStrings($strings); |
|
18 | - $cnt = count($singles); |
|
19 | - if ($cnt > 1 && $cnt < count($strings)) |
|
20 | - { |
|
21 | - // Remove the singles from the input, then prepend them as a new string |
|
22 | - $strings = array_diff_key($strings, $singles); |
|
23 | - array_unshift($strings, [array_values($singles)]); |
|
24 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function processStrings(array $strings) |
|
16 | + { |
|
17 | + $singles = $this->getSingleCharStrings($strings); |
|
18 | + $cnt = count($singles); |
|
19 | + if ($cnt > 1 && $cnt < count($strings)) |
|
20 | + { |
|
21 | + // Remove the singles from the input, then prepend them as a new string |
|
22 | + $strings = array_diff_key($strings, $singles); |
|
23 | + array_unshift($strings, [array_values($singles)]); |
|
24 | + } |
|
25 | 25 | |
26 | - return $strings; |
|
27 | - } |
|
26 | + return $strings; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Return an array of every single-char string in given list of strings |
|
31 | - * |
|
32 | - * @param array[] $strings |
|
33 | - * @return array[] |
|
34 | - */ |
|
35 | - protected function getSingleCharStrings(array $strings) |
|
36 | - { |
|
37 | - $singles = []; |
|
38 | - foreach ($strings as $k => $string) |
|
39 | - { |
|
40 | - if (count($string) === 1 && !is_array($string[0])) |
|
41 | - { |
|
42 | - $singles[$k] = $string; |
|
43 | - } |
|
44 | - } |
|
29 | + /** |
|
30 | + * Return an array of every single-char string in given list of strings |
|
31 | + * |
|
32 | + * @param array[] $strings |
|
33 | + * @return array[] |
|
34 | + */ |
|
35 | + protected function getSingleCharStrings(array $strings) |
|
36 | + { |
|
37 | + $singles = []; |
|
38 | + foreach ($strings as $k => $string) |
|
39 | + { |
|
40 | + if (count($string) === 1 && !is_array($string[0])) |
|
41 | + { |
|
42 | + $singles[$k] = $string; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | |
46 | - return $singles; |
|
47 | - } |
|
46 | + return $singles; |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -9,61 +9,61 @@ |
||
9 | 9 | |
10 | 10 | abstract class AbstractPass implements PassInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * @var bool Whether the current set of strings is optional |
|
14 | - */ |
|
15 | - protected $isOptional; |
|
12 | + /** |
|
13 | + * @var bool Whether the current set of strings is optional |
|
14 | + */ |
|
15 | + protected $isOptional; |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public function run(array $strings) |
|
21 | - { |
|
22 | - $strings = $this->beforeRun($strings); |
|
23 | - $strings = $this->processStrings($strings); |
|
24 | - $strings = $this->afterRun($strings); |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public function run(array $strings) |
|
21 | + { |
|
22 | + $strings = $this->beforeRun($strings); |
|
23 | + $strings = $this->processStrings($strings); |
|
24 | + $strings = $this->afterRun($strings); |
|
25 | 25 | |
26 | - return $strings; |
|
27 | - } |
|
26 | + return $strings; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Process the list of strings after the pass is run |
|
31 | - * |
|
32 | - * @param array[] $strings |
|
33 | - * @return array[] |
|
34 | - */ |
|
35 | - protected function afterRun(array $strings) |
|
36 | - { |
|
37 | - if ($this->isOptional && $strings[0] !== []) |
|
38 | - { |
|
39 | - array_unshift($strings, []); |
|
40 | - } |
|
29 | + /** |
|
30 | + * Process the list of strings after the pass is run |
|
31 | + * |
|
32 | + * @param array[] $strings |
|
33 | + * @return array[] |
|
34 | + */ |
|
35 | + protected function afterRun(array $strings) |
|
36 | + { |
|
37 | + if ($this->isOptional && $strings[0] !== []) |
|
38 | + { |
|
39 | + array_unshift($strings, []); |
|
40 | + } |
|
41 | 41 | |
42 | - return $strings; |
|
43 | - } |
|
42 | + return $strings; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Prepare the list of strings before the pass is run |
|
47 | - * |
|
48 | - * @param array[] $strings |
|
49 | - * @return array[] |
|
50 | - */ |
|
51 | - protected function beforeRun(array $strings) |
|
52 | - { |
|
53 | - $this->isOptional = (isset($strings[0]) && $strings[0] === []); |
|
54 | - if ($this->isOptional) |
|
55 | - { |
|
56 | - array_shift($strings); |
|
57 | - } |
|
45 | + /** |
|
46 | + * Prepare the list of strings before the pass is run |
|
47 | + * |
|
48 | + * @param array[] $strings |
|
49 | + * @return array[] |
|
50 | + */ |
|
51 | + protected function beforeRun(array $strings) |
|
52 | + { |
|
53 | + $this->isOptional = (isset($strings[0]) && $strings[0] === []); |
|
54 | + if ($this->isOptional) |
|
55 | + { |
|
56 | + array_shift($strings); |
|
57 | + } |
|
58 | 58 | |
59 | - return $strings; |
|
60 | - } |
|
59 | + return $strings; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Process a given list of strings |
|
64 | - * |
|
65 | - * @param array[] $strings |
|
66 | - * @return array[] |
|
67 | - */ |
|
68 | - abstract protected function processStrings(array $strings); |
|
62 | + /** |
|
63 | + * Process a given list of strings |
|
64 | + * |
|
65 | + * @param array[] $strings |
|
66 | + * @return array[] |
|
67 | + */ |
|
68 | + abstract protected function processStrings(array $strings); |
|
69 | 69 | } |
70 | 70 | \ No newline at end of file |
@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | interface PassInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Run this pass |
|
14 | - * |
|
15 | - * @param array[] $strings Original strings |
|
16 | - * @return array[] Modified strings |
|
17 | - */ |
|
18 | - public function run(array $strings); |
|
12 | + /** |
|
13 | + * Run this pass |
|
14 | + * |
|
15 | + * @param array[] $strings Original strings |
|
16 | + * @return array[] Modified strings |
|
17 | + */ |
|
18 | + public function run(array $strings); |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -9,54 +9,54 @@ |
||
9 | 9 | |
10 | 10 | class CoalesceSingleCharacterPrefix extends AbstractPass |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function processStrings(array $strings) |
|
16 | - { |
|
17 | - $newStrings = []; |
|
18 | - foreach ($this->getEligibleStrings($strings) as $suffix => $keys) |
|
19 | - { |
|
20 | - if (!isset($keys[1])) |
|
21 | - { |
|
22 | - continue; |
|
23 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function processStrings(array $strings) |
|
16 | + { |
|
17 | + $newStrings = []; |
|
18 | + foreach ($this->getEligibleStrings($strings) as $suffix => $keys) |
|
19 | + { |
|
20 | + if (!isset($keys[1])) |
|
21 | + { |
|
22 | + continue; |
|
23 | + } |
|
24 | 24 | |
25 | - // Create a new string to hold the merged strings and replace the first element with |
|
26 | - // an empty character class |
|
27 | - $newString = $strings[$keys[0]]; |
|
28 | - $newString[0] = []; |
|
29 | - foreach ($keys as $key) |
|
30 | - { |
|
31 | - $newString[0][] = [$strings[$key][0]]; |
|
32 | - unset($strings[$key]); |
|
33 | - } |
|
34 | - $newStrings[] = $newString; |
|
35 | - } |
|
25 | + // Create a new string to hold the merged strings and replace the first element with |
|
26 | + // an empty character class |
|
27 | + $newString = $strings[$keys[0]]; |
|
28 | + $newString[0] = []; |
|
29 | + foreach ($keys as $key) |
|
30 | + { |
|
31 | + $newString[0][] = [$strings[$key][0]]; |
|
32 | + unset($strings[$key]); |
|
33 | + } |
|
34 | + $newStrings[] = $newString; |
|
35 | + } |
|
36 | 36 | |
37 | - return array_merge($newStrings, $strings); |
|
38 | - } |
|
37 | + return array_merge($newStrings, $strings); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Get a list of keys of strings eligible to be merged together, grouped by suffix |
|
42 | - * |
|
43 | - * @param array[] $strings |
|
44 | - * @return array[] |
|
45 | - */ |
|
46 | - protected function getEligibleStrings(array $strings) |
|
47 | - { |
|
48 | - $eligibleStrings = []; |
|
49 | - foreach ($strings as $k => $string) |
|
50 | - { |
|
51 | - if (is_array($string[0]) || !isset($string[1])) |
|
52 | - { |
|
53 | - continue; |
|
54 | - } |
|
40 | + /** |
|
41 | + * Get a list of keys of strings eligible to be merged together, grouped by suffix |
|
42 | + * |
|
43 | + * @param array[] $strings |
|
44 | + * @return array[] |
|
45 | + */ |
|
46 | + protected function getEligibleStrings(array $strings) |
|
47 | + { |
|
48 | + $eligibleStrings = []; |
|
49 | + foreach ($strings as $k => $string) |
|
50 | + { |
|
51 | + if (is_array($string[0]) || !isset($string[1])) |
|
52 | + { |
|
53 | + continue; |
|
54 | + } |
|
55 | 55 | |
56 | - $suffix = serialize(array_slice($string, 1)); |
|
57 | - $eligibleStrings[$suffix][] = $k; |
|
58 | - } |
|
56 | + $suffix = serialize(array_slice($string, 1)); |
|
57 | + $eligibleStrings[$suffix][] = $k; |
|
58 | + } |
|
59 | 59 | |
60 | - return $eligibleStrings; |
|
61 | - } |
|
60 | + return $eligibleStrings; |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | \ No newline at end of file |
@@ -9,53 +9,53 @@ |
||
9 | 9 | |
10 | 10 | class MergeSuffix extends AbstractPass |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function processStrings(array $strings) |
|
16 | - { |
|
17 | - if (count($strings) < 2) |
|
18 | - { |
|
19 | - return $strings; |
|
20 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function processStrings(array $strings) |
|
16 | + { |
|
17 | + if (count($strings) < 2) |
|
18 | + { |
|
19 | + return $strings; |
|
20 | + } |
|
21 | 21 | |
22 | - $newString = []; |
|
23 | - while ($this->hasMatchingSuffix($strings)) |
|
24 | - { |
|
25 | - array_unshift($newString, end($strings[0])); |
|
26 | - $i = count($strings); |
|
27 | - while (--$i >= 0) |
|
28 | - { |
|
29 | - array_pop($strings[$i]); |
|
30 | - } |
|
31 | - } |
|
32 | - if (empty($newString)) |
|
33 | - { |
|
34 | - return $strings; |
|
35 | - } |
|
22 | + $newString = []; |
|
23 | + while ($this->hasMatchingSuffix($strings)) |
|
24 | + { |
|
25 | + array_unshift($newString, end($strings[0])); |
|
26 | + $i = count($strings); |
|
27 | + while (--$i >= 0) |
|
28 | + { |
|
29 | + array_pop($strings[$i]); |
|
30 | + } |
|
31 | + } |
|
32 | + if (empty($newString)) |
|
33 | + { |
|
34 | + return $strings; |
|
35 | + } |
|
36 | 36 | |
37 | - array_unshift($newString, $strings); |
|
37 | + array_unshift($newString, $strings); |
|
38 | 38 | |
39 | - return [$newString]; |
|
40 | - } |
|
39 | + return [$newString]; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Test whether all given strings have the same last element |
|
44 | - * |
|
45 | - * @param array[] $strings |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - protected function hasMatchingSuffix(array $strings) |
|
49 | - { |
|
50 | - $suffix = end($strings[1]); |
|
51 | - foreach ($strings as $string) |
|
52 | - { |
|
53 | - if (end($string) !== $suffix) |
|
54 | - { |
|
55 | - return false; |
|
56 | - } |
|
57 | - } |
|
42 | + /** |
|
43 | + * Test whether all given strings have the same last element |
|
44 | + * |
|
45 | + * @param array[] $strings |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + protected function hasMatchingSuffix(array $strings) |
|
49 | + { |
|
50 | + $suffix = end($strings[1]); |
|
51 | + foreach ($strings as $string) |
|
52 | + { |
|
53 | + if (end($string) !== $suffix) |
|
54 | + { |
|
55 | + return false; |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - return ($suffix !== false); |
|
60 | - } |
|
59 | + return ($suffix !== false); |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | \ No newline at end of file |
@@ -11,45 +11,45 @@ |
||
11 | 11 | |
12 | 12 | class Recurse extends AbstractPass |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Runner |
|
16 | - */ |
|
17 | - protected $runner; |
|
14 | + /** |
|
15 | + * @var Runner |
|
16 | + */ |
|
17 | + protected $runner; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param Runner $runner |
|
21 | - */ |
|
22 | - public function __construct(Runner $runner) |
|
23 | - { |
|
24 | - $this->runner = $runner; |
|
25 | - } |
|
19 | + /** |
|
20 | + * @param Runner $runner |
|
21 | + */ |
|
22 | + public function __construct(Runner $runner) |
|
23 | + { |
|
24 | + $this->runner = $runner; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - */ |
|
30 | - protected function processStrings(array $strings) |
|
31 | - { |
|
32 | - return array_map([$this, 'recurseString'], $strings); |
|
33 | - } |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + */ |
|
30 | + protected function processStrings(array $strings) |
|
31 | + { |
|
32 | + return array_map([$this, 'recurseString'], $strings); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Recurse into given string and run all passes on each element |
|
37 | - * |
|
38 | - * @param array $string |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - protected function recurseString(array $string) |
|
42 | - { |
|
43 | - $isOptional = $this->isOptional; |
|
44 | - foreach ($string as $k => $element) |
|
45 | - { |
|
46 | - if (is_array($element)) |
|
47 | - { |
|
48 | - $string[$k] = $this->runner->run($element); |
|
49 | - } |
|
50 | - } |
|
51 | - $this->isOptional = $isOptional; |
|
35 | + /** |
|
36 | + * Recurse into given string and run all passes on each element |
|
37 | + * |
|
38 | + * @param array $string |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + protected function recurseString(array $string) |
|
42 | + { |
|
43 | + $isOptional = $this->isOptional; |
|
44 | + foreach ($string as $k => $element) |
|
45 | + { |
|
46 | + if (is_array($element)) |
|
47 | + { |
|
48 | + $string[$k] = $this->runner->run($element); |
|
49 | + } |
|
50 | + } |
|
51 | + $this->isOptional = $isOptional; |
|
52 | 52 | |
53 | - return $string; |
|
54 | - } |
|
53 | + return $string; |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | \ No newline at end of file |