| Conditions | 13 |
| Paths | 10 |
| Total Lines | 45 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 108 | protected function appendFirstUriPartIfValidDimension(&$path) { |
||
| 109 | $requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/'); |
||
| 110 | $matches = []; |
||
| 111 | preg_match(\TYPO3\Neos\Routing\FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches); |
||
| 112 | if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) { |
||
| 113 | return; |
||
| 114 | } |
||
| 115 | |||
| 116 | $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets(); |
||
| 117 | if (count($dimensionPresets) === 0) { |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | |||
| 121 | $firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']); |
||
| 122 | if ($this->supportEmptySegmentForDimensions) { |
||
| 123 | foreach ($firstUriPartExploded as $uriSegment) { |
||
| 124 | $uriSegmentIsValid = false; |
||
| 125 | foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
||
| 126 | $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
||
| 127 | if ($preset !== null) { |
||
| 128 | $uriSegmentIsValid = true; |
||
| 129 | break; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | if (!$uriSegmentIsValid) { |
||
| 133 | return; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | if (count($firstUriPartExploded) !== count($dimensionPresets)) { |
||
| 138 | $this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path); |
||
| 139 | return; |
||
| 140 | } |
||
| 141 | foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
||
| 142 | $uriSegment = array_shift($firstUriPartExploded); |
||
| 143 | $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
||
| 144 | if ($preset === null) { |
||
| 145 | $this->appendDefaultDimensionPresetUriSegments($dimensionPresets, $path); |
||
| 146 | return; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $path = $matches['firstUriPart'] . '/' . $path; |
||
| 152 | } |
||
| 153 | |||
| 167 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.