Conditions | 19 |
Paths | 127 |
Total Lines | 40 |
Code Lines | 20 |
Lines | 30 |
Ratio | 75 % |
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 |
||
74 | protected function isValid($width, $height, array $configuration) |
||
75 | { |
||
76 | View Code Duplication | if (isset($configuration['MinWidth']) && $this->validateConfig('MinWidth', $configuration)) { |
|
77 | if ($width < $configuration['MinWidth']) { |
||
78 | throw new ValidationException('Minimum width must be '.$configuration['MinWidth'].'px'); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | View Code Duplication | if (isset($configuration['MaxWidth']) && $this->validateConfig('MaxWidth', $configuration)) { |
|
83 | if ($width > $configuration['MaxWidth']) { |
||
84 | throw new ValidationException('Maximum width must be '.$configuration['MaxWidth'].'px'); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | View Code Duplication | if (isset($configuration['MinHeight']) && $this->validateConfig('MinHeight', $configuration)) { |
|
89 | if ($height < $configuration['MinHeight']) { |
||
90 | throw new ValidationException('Minimum height must be '.$configuration['MinHeight'].'px'); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | View Code Duplication | if (isset($configuration['MaxHeight']) && $this->validateConfig('MaxHeight', $configuration)) { |
|
95 | if ($height > $configuration['MaxHeight']) { |
||
96 | throw new ValidationException('Minimum height must be '.$configuration['MaxHeight'].'px'); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $ratio = round($width / $height, 2); |
||
101 | |||
102 | View Code Duplication | if (isset($configuration['MinRatio']) && $this->validateConfig('MinRatio', $configuration, true)) { |
|
103 | if ($ratio < $configuration['MinRatio']) { |
||
104 | throw new ValidationException('Minimum ratio must be '.$configuration['MinRatio']); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | View Code Duplication | if (isset($configuration['MaxRatio']) && $this->validateConfig('MaxRatio', $configuration, true)) { |
|
109 | if ($ratio > $configuration['MaxRatio']) { |
||
110 | throw new ValidationException('Maximum ratio must be '.$configuration['MaxRatio']); |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 | |||
139 |