| 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 |
||
| 42 | protected function testConfig() |
||
| 43 | { |
||
| 44 | foreach ($this->configTests() as $property => $test) { |
||
| 45 | |||
| 46 | if (!property_exists($this, $property)) { |
||
| 47 | throw new GridViewConfigException( |
||
| 48 | 'Unable to test ' . get_class($this) . ': property ' . $property . ' does not exist' |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | if (is_scalar($test)) { |
||
| 53 | |||
| 54 | $testPassed = true; |
||
| 55 | |||
| 56 | switch ($test) { |
||
| 57 | case 'int': |
||
| 58 | $testPassed = is_numeric($this->$property); |
||
| 59 | break; |
||
| 60 | |||
| 61 | case 'string': |
||
| 62 | $testPassed = is_string($this->$property); |
||
| 63 | break; |
||
| 64 | |||
| 65 | case 'array': |
||
| 66 | $testPassed = is_array($this->$property); |
||
| 67 | break; |
||
| 68 | |||
| 69 | case 'closure': |
||
| 70 | $testPassed = $this->$property instanceof \Closure; |
||
| 71 | break; |
||
| 72 | |||
| 73 | case 'any': |
||
| 74 | break; |
||
| 75 | |||
| 76 | default: |
||
| 77 | $testPassed = is_subclass_of($this->$property, $test); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (!$testPassed) { |
||
| 81 | throw new GridViewConfigException(' |
||
| 82 | Test ' . $test . ' has failed on ' . get_class($this) . '::' . $property |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.