| Conditions | 11 |
| Paths | 65 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 67 | protected function fetch() { |
||
| 68 | $client = $this->clientService->newClient(); |
||
| 69 | $response = $client->get($this->endpointUrl); |
||
| 70 | $responseJson = []; |
||
| 71 | $responseJson['data'] = json_decode($response->getBody(), true); |
||
| 72 | $responseJson['timestamp'] = $this->timeFactory->getTime(); |
||
| 73 | $response = $responseJson; |
||
| 74 | |||
| 75 | $ncVersion = $this->config->getSystemValue('version'); |
||
| 76 | $ncMajorVersion = explode('.', $ncVersion)[0]; |
||
| 77 | foreach($response['data'] as $dataKey => $app) { |
||
| 78 | $releases = []; |
||
| 79 | |||
| 80 | // Filter all compatible releases |
||
| 81 | foreach($app['releases'] as $release) { |
||
| 82 | // Exclude all nightly releases |
||
| 83 | if($release['isNightly'] === false) { |
||
| 84 | // Exclude all versions not compatible with the current version |
||
| 85 | $versionParser = new VersionParser(); |
||
| 86 | $version = $versionParser->getVersion($release['rawPlatformVersionSpec']); |
||
| 87 | |||
| 88 | if( |
||
| 89 | // Major version is bigger or equals to the minimum version of the app |
||
| 90 | version_compare($ncMajorVersion, $version->getMinimumVersion(), '>=') |
||
| 91 | // Major version is smaller or equals to the maximum version of the app |
||
| 92 | && version_compare($ncMajorVersion, $version->getMaximumVersion(), '<=')) { |
||
| 93 | $releases[] = $release; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // Get the highest version |
||
| 99 | $versions = []; |
||
| 100 | foreach($releases as $release) { |
||
| 101 | $versions[] = $release['version']; |
||
| 102 | } |
||
| 103 | usort($versions, 'version_compare'); |
||
| 104 | $versions = array_reverse($versions); |
||
| 105 | $compatible = false; |
||
| 106 | if(isset($versions[0])) { |
||
| 107 | $highestVersion = $versions[0]; |
||
| 108 | foreach ($releases as $release) { |
||
| 109 | if ((string)$release['version'] === (string)$highestVersion) { |
||
| 110 | $compatible = true; |
||
| 111 | $response['data'][$dataKey]['releases'] = [$release]; |
||
| 112 | break; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | if(!$compatible) { |
||
| 117 | unset($response['data'][$dataKey]); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $response; |
||
| 122 | } |
||
| 123 | } |
||
| 124 |
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.