| Conditions | 12 |
| Paths | 65 |
| Total Lines | 54 |
| Code Lines | 32 |
| 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 |
||
| 60 | protected function fetch($ETag, $content) { |
||
| 61 | /** @var mixed[] $response */ |
||
| 62 | $response = parent::fetch($ETag, $content); |
||
| 63 | |||
| 64 | $ncVersion = $this->getVersion(); |
||
| 65 | $ncMajorVersion = explode('.', $ncVersion)[0]; |
||
| 66 | foreach($response['data'] as $dataKey => $app) { |
||
| 67 | $releases = []; |
||
| 68 | |||
| 69 | // Filter all compatible releases |
||
| 70 | foreach($app['releases'] as $release) { |
||
| 71 | // Exclude all nightly and pre-releases |
||
| 72 | if($release['isNightly'] === false |
||
| 73 | && strpos($release['version'], '-') === false) { |
||
| 74 | // Exclude all versions not compatible with the current version |
||
| 75 | $versionParser = new VersionParser(); |
||
| 76 | $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
||
| 77 | if ( |
||
| 78 | // Major version is bigger or equals to the minimum version of the app |
||
| 79 | version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
||
| 80 | // Major version is smaller or equals to the maximum version of the app |
||
| 81 | && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=') |
||
| 82 | ) { |
||
| 83 | $releases[] = $release; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | // Get the highest version |
||
| 89 | $versions = []; |
||
| 90 | foreach($releases as $release) { |
||
| 91 | $versions[] = $release['version']; |
||
| 92 | } |
||
| 93 | usort($versions, 'version_compare'); |
||
| 94 | $versions = array_reverse($versions); |
||
| 95 | $compatible = false; |
||
| 96 | if(isset($versions[0])) { |
||
| 97 | $highestVersion = $versions[0]; |
||
| 98 | foreach ($releases as $release) { |
||
| 99 | if ((string)$release['version'] === (string)$highestVersion) { |
||
| 100 | $compatible = true; |
||
| 101 | $response['data'][$dataKey]['releases'] = [$release]; |
||
| 102 | break; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | if(!$compatible) { |
||
| 107 | unset($response['data'][$dataKey]); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $response['data'] = array_values($response['data']); |
||
| 112 | return $response; |
||
| 113 | } |
||
| 114 | |||
| 133 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.