| Conditions | 5 |
| Paths | 9 |
| Total Lines | 59 |
| Code Lines | 30 |
| 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 |
||
| 126 | private function rebuildConfigsIfOutdated(): void |
||
| 127 | { |
||
| 128 | // Only rebuild if neccesary |
||
| 129 | if ($this->configs) { |
||
|
|
|||
| 130 | return; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Base configs |
||
| 134 | $configs = [ |
||
| 135 | Configs::SUITES => [], |
||
| 136 | Configs::CLI => [], |
||
| 137 | ]; |
||
| 138 | |||
| 139 | $defaults = []; |
||
| 140 | |||
| 141 | // Merge with repositories |
||
| 142 | foreach ($this->repositories as $repository) { |
||
| 143 | $configs = array_merge($configs, $repository->getConfigs()); |
||
| 144 | |||
| 145 | // Merge defaults separatly to account for multiple default definitions |
||
| 146 | $defaults = array_merge( |
||
| 147 | $defaults, |
||
| 148 | (array)($repository->getConfigs()[Configs::DEFAULTS] ?? []) |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | |||
| 152 | // Create default suite if none exists |
||
| 153 | if (empty($configs[Configs::SUITES])) { |
||
| 154 | $configs[Configs::SUITES][Configs::DEFAULT_SUITE_NAME] = []; |
||
| 155 | } |
||
| 156 | |||
| 157 | // Build suite objects |
||
| 158 | $this->suites = []; |
||
| 159 | |||
| 160 | foreach ($configs[Configs::SUITES] as $name => $suite) { |
||
| 161 | // Merge suite with default configs |
||
| 162 | $suite = array_merge($defaults, (array)$suite); |
||
| 163 | |||
| 164 | // Merge suite with cli configs |
||
| 165 | $suite = array_merge($suite, (array)$configs[Configs::CLI]); |
||
| 166 | |||
| 167 | // Build suite |
||
| 168 | $this->suites[] = new Suite( |
||
| 169 | name: (string)$name, |
||
| 170 | active: (bool)($suite[Configs::ACTIVE] ?? true), |
||
| 171 | inputLanguage: (string)($suite[Configs::INPUT_LANGUAGE] ?? ''), |
||
| 172 | runner: (string)($suite[Configs::RUNNER] ?? ''), |
||
| 173 | includePaths: (array)($suite[Configs::INCLUDE_PATHS] ?? []), |
||
| 174 | excludePaths: (array)($suite[Configs::EXCLUDE_PATHS] ?? []), |
||
| 175 | fileExtensions: (array)($suite[Configs::FILE_EXTENSIONS] ?? []), |
||
| 176 | stopOnFailure: (bool)($suite[Configs::STOP_ON_FAILURE] ?? false), |
||
| 177 | globalAttributes: (array)($suite[Configs::GLOBAL_ATTRIBUTES] ?? []), |
||
| 178 | filter: (string)($suite[Configs::FILTER] ?? ''), |
||
| 179 | readFromStdin: (bool)($suite[Configs::STDIN] ?? false), |
||
| 180 | ); |
||
| 181 | } |
||
| 182 | |||
| 183 | // Store configs |
||
| 184 | $this->configs = array_merge($configs, $configs[Configs::CLI]); |
||
| 185 | } |
||
| 187 |
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.