Conditions | 5 |
Paths | 5 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
81 | public function generateQuery(string $namespaceAlias, array $path): string |
||
82 | { |
||
83 | $query = ''; |
||
84 | |||
85 | while (\count($path)) { |
||
86 | $p = \array_shift($path); |
||
87 | $next = $path[0] ?? null; |
||
88 | |||
89 | // Reduce to only the upper/lower of the active letters |
||
90 | // ≈30-35% faster than the full alphabet |
||
91 | $pLet = \count_chars($p, 3); |
||
92 | $pLow = \mb_strtolower($pLet); |
||
93 | $pUp = \mb_strtoupper($pLet); |
||
94 | |||
95 | if (\is_int($next)) { |
||
96 | if ($this->caseSensitive) { |
||
97 | // case; next |
||
98 | $query .= \sprintf( |
||
99 | '/%s:%s[position() = %d]', |
||
100 | $namespaceAlias, |
||
101 | $p, |
||
102 | \array_shift($path) + 1 |
||
103 | ); |
||
104 | } else { |
||
105 | // icase; next |
||
106 | $query .= \sprintf( |
||
107 | '/%s:*[translate(name(), \'%s\', \'%s\') = \'%s\'][position() = %d]', |
||
108 | $namespaceAlias, |
||
109 | $pUp, |
||
110 | $pLow, |
||
111 | $p, |
||
112 | \array_shift($path) + 1 |
||
113 | ); |
||
114 | } |
||
115 | } else { |
||
116 | if ($this->caseSensitive) { |
||
117 | // case; no-next |
||
118 | $query .= \sprintf( |
||
119 | '/%s:%s', |
||
120 | $namespaceAlias, |
||
121 | $p |
||
122 | ); |
||
123 | } else { |
||
124 | // icase; no-next |
||
125 | $query .= \sprintf( |
||
126 | '/%s:*[translate(name(), \'%s\', \'%s\') = \'%s\']', |
||
127 | $namespaceAlias, |
||
128 | $pUp, |
||
129 | $pLow, |
||
130 | $p |
||
131 | ); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | |||
136 | return $query; |
||
137 | } |
||
139 |