| Conditions | 13 |
| Paths | 22 |
| Total Lines | 57 |
| 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 |
||
| 37 | protected function testConfig() |
||
| 38 | { |
||
| 39 | foreach ($this->configTests() as $property => $tests) { |
||
| 40 | |||
| 41 | if (!property_exists($this, $property)) { |
||
| 42 | throw new GridViewConfigException( |
||
| 43 | 'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist' |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | |||
| 47 | $testPassed = true; |
||
| 48 | $testMessage = 'Validation failed'; |
||
| 49 | |||
| 50 | foreach (explode('|', $tests) as $test) { |
||
| 51 | |||
| 52 | switch ($test) { |
||
| 53 | case 'int': |
||
| 54 | $testPassed = is_numeric($this->$property); |
||
| 55 | $testMessage = 'Property should be numeric'; |
||
| 56 | break; |
||
| 57 | |||
| 58 | case 'string': |
||
| 59 | $testPassed = is_string($this->$property); |
||
| 60 | $testMessage = 'Property should be a string'; |
||
| 61 | break; |
||
| 62 | |||
| 63 | case 'array': |
||
| 64 | $testPassed = is_array($this->$property); |
||
| 65 | $testMessage = 'Property should be an array'; |
||
| 66 | break; |
||
| 67 | |||
| 68 | case 'closure': |
||
| 69 | $testPassed = $this->$property instanceof Closure; |
||
| 70 | $testMessage = 'Property should be a valid callback (Closure instance)'; |
||
| 71 | break; |
||
| 72 | |||
| 73 | case 'boolean': |
||
| 74 | $testPassed = is_bool($this->$property); |
||
| 75 | $testMessage = 'Property should be boolean'; |
||
| 76 | break; |
||
| 77 | |||
| 78 | case 'any': |
||
| 79 | break; |
||
| 80 | |||
| 81 | default: |
||
| 82 | $testPassed = $testPassed || is_a($this->$property, $test) || is_subclass_of($this->$property, $test); |
||
|
|
|||
| 83 | $testMessage = 'Property should be ' . $test . ' instance/class reference, got ' . print_r($this->$property, 1); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | if (!$testPassed) { |
||
| 88 | throw new GridViewConfigException( |
||
| 89 | 'Tests ' . $tests . ' has failed on ' . get_class($this) . '::' . $property . ': ' . $testMessage |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |