| Conditions | 14 |
| Paths | 20 |
| Total Lines | 42 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 72 | protected function preprocessPathString($path) |
||
| 73 | { |
||
| 74 | // If the path is null, make sure to give it our match-all value |
||
| 75 | $path = (null === $path) ? static::NULL_PATH_VALUE : (string) $path; |
||
| 76 | |||
| 77 | // If a custom regular expression (or negated custom regex) |
||
| 78 | if ($this->namespace && |
||
| 79 | (isset($path[0]) && $path[0] === '@') || |
||
| 80 | (isset($path[0]) && $path[0] === '!' && isset($path[1]) && $path[1] === '@') |
||
| 81 | ) { |
||
| 82 | // Is it negated? |
||
| 83 | if ($path[0] === '!') { |
||
| 84 | $negate = true; |
||
| 85 | $path = substr($path, 2); |
||
| 86 | } else { |
||
| 87 | $negate = false; |
||
| 88 | $path = substr($path, 1); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Regex anchored to front of string |
||
| 92 | if ($path[0] === '^') { |
||
| 93 | $path = substr($path, 1); |
||
| 94 | } else { |
||
| 95 | $path = '.*' . $path; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($negate) { |
||
| 99 | $path = '@^' . $this->namespace . '(?!' . $path . ')'; |
||
| 100 | } else { |
||
| 101 | $path = '@^' . $this->namespace . $path; |
||
| 102 | } |
||
| 103 | |||
| 104 | } elseif ($this->namespace && $this->pathIsNull($path)) { |
||
| 105 | // Empty route with namespace is a match-all |
||
| 106 | $path = '@^' . $this->namespace . '(/|$)'; |
||
| 107 | } else { |
||
| 108 | // Just prepend our namespace |
||
| 109 | $path = $this->namespace . $path; |
||
| 110 | } |
||
| 111 | |||
| 112 | return $path; |
||
| 113 | } |
||
| 114 | |||
| 135 |