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