| Conditions | 22 |
| Paths | 208 |
| Total Lines | 44 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 35 | public function validate($manifest) |
||
| 36 | { |
||
| 37 | $errors = array(); |
||
| 38 | $linksSections = array('require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest'); |
||
| 39 | |||
| 40 | if (isset($manifest['config']['sort-packages']) && $manifest['config']['sort-packages']) { |
||
| 41 | foreach ($linksSections as $linksSection) { |
||
| 42 | if (array_key_exists($linksSection, $manifest) && !$this->packagesAreSorted($manifest[$linksSection])) { |
||
| 43 | array_push($errors, 'Links under '.$linksSection.' section are not sorted.'); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | if (true === $this->config['php'] && |
||
| 49 | (array_key_exists('require-dev', $manifest) || array_key_exists('require', $manifest))) { |
||
| 50 | $isOnRequireDev = array_key_exists('require-dev', $manifest) && array_key_exists('php', $manifest['require-dev']); |
||
| 51 | $isOnRequire = array_key_exists('require', $manifest) && array_key_exists('php', $manifest['require']); |
||
| 52 | |||
| 53 | if ($isOnRequireDev) { |
||
| 54 | array_push($errors, 'PHP requirement should be in the require section, not in the require-dev section.'); |
||
| 55 | } elseif (!$isOnRequire) { |
||
| 56 | array_push($errors, 'You must specifiy the PHP requirement.'); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if (true === $this->config['type'] && !array_key_exists('type', $manifest)) { |
||
| 61 | array_push($errors, 'The package type is not specified.'); |
||
| 62 | } |
||
| 63 | |||
| 64 | if (true === $this->config['minimum-stability'] && array_key_exists('minimum-stability', $manifest) && |
||
| 65 | array_key_exists('type', $manifest) && 'project' !== $manifest['type']) { |
||
| 66 | array_push($errors, 'The minimum-stability should be only used for project packages.'); |
||
| 67 | } |
||
| 68 | |||
| 69 | if (true === $this->config['version-constraints']) { |
||
| 70 | foreach ($linksSections as $linksSection) { |
||
| 71 | if (array_key_exists($linksSection, $manifest)) { |
||
| 72 | $errors = array_merge($errors, $this->validateVersionConstraints($manifest[$linksSection])); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | return $errors; |
||
| 78 | } |
||
| 79 | |||
| 145 |