Conditions | 10 |
Paths | 34 |
Total Lines | 39 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
23 | public function __construct(array $resources) |
||
24 | { |
||
25 | if (!isset($resources['resources'])) { |
||
26 | throw new RuntimeException( |
||
27 | 'resources element is not defined' |
||
28 | ); |
||
29 | } |
||
30 | |||
31 | $this->rewrites = []; |
||
32 | $this->globals = []; |
||
33 | |||
34 | foreach ($resources['resources'] as $item) { |
||
35 | if (isset($item['constraints'])) { |
||
36 | foreach ($item['constraints'] as $name => $value) { |
||
37 | if (!in_array($name, $this->allowed)) { |
||
38 | throw new RuntimeException( |
||
39 | 'Invalid constraint: ' |
||
40 | . 'name ' . $name |
||
41 | . '; value ' . $value |
||
42 | ); |
||
43 | } |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | |||
48 | foreach ($resources['resources'] as $item) { |
||
49 | if (isset($item['rewrite'])) { |
||
50 | foreach ($item['rewrite'] as $field => $rewriteRule) { |
||
51 | $this->rewrites[$field] = $rewriteRule; |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | if (isset($resources['globals'])) { |
||
57 | $this->globals = $resources['globals']; |
||
58 | } |
||
59 | |||
60 | $this->resources = $resources; |
||
61 | } |
||
62 | |||
124 |