| Conditions | 13 |
| Paths | 10 |
| Total Lines | 43 |
| Code Lines | 29 |
| Lines | 14 |
| Ratio | 32.56 % |
| Changes | 1 | ||
| 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 |
||
| 99 | protected function appendFirstUriPartIfValidDimension(&$path) { |
||
| 100 | $requestPath = ltrim($this->controllerContext->getRequest()->getHttpRequest()->getUri()->getPath(), '/'); |
||
| 101 | $matches = []; |
||
| 102 | preg_match(\TYPO3\Neos\Routing\FrontendNodeRoutePartHandler::DIMENSION_REQUEST_PATH_MATCHER, $requestPath, $matches); |
||
| 103 | if (!isset($matches['firstUriPart']) && !isset($matches['dimensionPresetUriSegments'])) { |
||
| 104 | return; |
||
| 105 | } |
||
| 106 | |||
| 107 | $dimensionPresets = $this->contentDimensionPresetSource->getAllPresets(); |
||
| 108 | if (count($dimensionPresets) === 0) { |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | $firstUriPartExploded = explode('_', $matches['firstUriPart'] ?: $matches['dimensionPresetUriSegments']); |
||
| 113 | if ($this->supportEmptySegmentForDimensions) { |
||
| 114 | foreach ($firstUriPartExploded as $uriSegment) { |
||
| 115 | $uriSegmentIsValid = false; |
||
| 116 | View Code Duplication | foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
| 117 | $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
||
| 118 | if ($preset !== null) { |
||
| 119 | $uriSegmentIsValid = true; |
||
| 120 | break; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | if (!$uriSegmentIsValid) { |
||
| 124 | return; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } else { |
||
| 128 | if (count($firstUriPartExploded) === count($dimensionPresets)) { |
||
| 129 | return; |
||
| 130 | } |
||
| 131 | View Code Duplication | foreach ($dimensionPresets as $dimensionName => $dimensionPreset) { |
|
| 132 | $uriSegment = array_shift($firstUriPartExploded); |
||
| 133 | $preset = $this->contentDimensionPresetSource->findPresetByUriSegment($dimensionName, $uriSegment); |
||
| 134 | if ($preset === null) { |
||
| 135 | return; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | $path = $matches['firstUriPart'] . '/' . $path; |
||
| 141 | } |
||
| 142 | |||
| 144 |
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.