| Conditions | 10 |
| Paths | 15 |
| Total Lines | 46 |
| 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 |
||
| 33 | public static function testConfig($object, array $tests) |
||
| 34 | { |
||
| 35 | foreach ($tests as $property => $test) { |
||
| 36 | |||
| 37 | if (!property_exists($object, $property)) { |
||
| 38 | throw new GridViewConfigException( |
||
| 39 | 'Unable to test ' . get_class($object) . ': property ' . $property . ' does not exist' |
||
| 40 | ); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (is_scalar($test)) { |
||
| 44 | |||
| 45 | $testPassed = true; |
||
| 46 | |||
| 47 | switch ($test) { |
||
| 48 | case 'int': |
||
| 49 | $testPassed = is_numeric($object->$property); |
||
| 50 | break; |
||
| 51 | |||
| 52 | case 'string': |
||
| 53 | $testPassed = is_string($object->$property); |
||
| 54 | break; |
||
| 55 | |||
| 56 | case 'array': |
||
| 57 | $testPassed = is_array($object->$property); |
||
| 58 | break; |
||
| 59 | |||
| 60 | case 'closure': |
||
| 61 | $testPassed = $object->$property instanceof \Closure; |
||
| 62 | break; |
||
| 63 | |||
| 64 | case 'any': |
||
| 65 | break; |
||
| 66 | |||
| 67 | default: |
||
| 68 | $testPassed = is_subclass_of($object->$property, $test); |
||
|
|
|||
| 69 | } |
||
| 70 | |||
| 71 | if (!$testPassed) { |
||
| 72 | throw new GridViewConfigException(' |
||
| 73 | Test ' . $test . ' has failed on ' . get_class($object) . '::' . $property |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 99 | } |