| Conditions | 14 |
| Paths | 265 |
| Total Lines | 70 |
| Code Lines | 42 |
| Lines | 14 |
| Ratio | 20 % |
| 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 |
||
| 73 | public function analyse($appId) { |
||
| 74 | $appPath = \OC_App::getAppPath($appId); |
||
| 75 | if ($appPath === false) { |
||
| 76 | throw new \RuntimeException("No app with given id <$appId> known."); |
||
| 77 | } |
||
| 78 | |||
| 79 | $errors = []; |
||
| 80 | |||
| 81 | $info = $this->infoParser->parse($appPath . '/appinfo/info.xml'); |
||
| 82 | |||
| 83 | View Code Duplication | if (!isset($info['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
| 84 | $errors[] = [ |
||
| 85 | 'type' => 'missingRequirement', |
||
| 86 | 'field' => 'min', |
||
| 87 | ]; |
||
| 88 | $this->emit('InfoChecker', 'missingRequirement', ['min']); |
||
| 89 | } |
||
| 90 | |||
| 91 | View Code Duplication | if (!isset($info['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
| 92 | $errors[] = [ |
||
| 93 | 'type' => 'missingRequirement', |
||
| 94 | 'field' => 'max', |
||
| 95 | ]; |
||
| 96 | $this->emit('InfoChecker', 'missingRequirement', ['max']); |
||
| 97 | } |
||
| 98 | |||
| 99 | foreach ($info as $key => $value) { |
||
| 100 | if(is_array($value)) { |
||
| 101 | $value = json_encode($value); |
||
| 102 | } |
||
| 103 | if (in_array($key, $this->mandatoryFields)) { |
||
| 104 | $this->emit('InfoChecker', 'mandatoryFieldFound', [$key, $value]); |
||
| 105 | continue; |
||
| 106 | } |
||
| 107 | |||
| 108 | if (in_array($key, $this->optionalFields)) { |
||
| 109 | $this->emit('InfoChecker', 'optionalFieldFound', [$key, $value]); |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | if (in_array($key, $this->deprecatedFields)) { |
||
| 114 | // skip empty arrays - empty arrays for remote and public are always added |
||
| 115 | if($value === '[]' && in_array($key, ['public', 'remote', 'info'])) { |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | $this->emit('InfoChecker', 'deprecatedFieldFound', [$key, $value]); |
||
| 119 | continue; |
||
| 120 | } |
||
| 121 | |||
| 122 | $this->emit('InfoChecker', 'unusedFieldFound', [$key, $value]); |
||
| 123 | } |
||
| 124 | |||
| 125 | foreach ($this->mandatoryFields as $key) { |
||
| 126 | if(!isset($info[$key])) { |
||
| 127 | $this->emit('InfoChecker', 'mandatoryFieldMissing', [$key]); |
||
| 128 | $errors[] = [ |
||
| 129 | 'type' => 'mandatoryFieldMissing', |
||
| 130 | 'field' => $key, |
||
| 131 | ]; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $versionFile = $appPath . '/appinfo/version'; |
||
| 136 | if (is_file($versionFile)) { |
||
| 137 | $version = trim(file_get_contents($versionFile)); |
||
| 138 | $this->emit('InfoChecker', 'migrateVersion', [$version]); |
||
| 139 | } |
||
| 140 | |||
| 141 | return $errors; |
||
| 142 | } |
||
| 143 | } |
||
| 144 |