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