| Conditions | 1 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 38 |
| 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 |
||
| 46 | public function propertiesToBeTested() : array |
||
| 47 | { |
||
| 48 | $astLocator = (new BetterReflection())->astLocator(); |
||
| 49 | |||
| 50 | $fromLocator = new StringSourceLocator( |
||
| 51 | <<<'PHP' |
||
| 52 | <?php |
||
| 53 | |||
| 54 | abstract class TheClass { |
||
| 55 | public function publicConcreteToAbstract() {} |
||
| 56 | public abstract function publicAbstractToConcrete() {} |
||
| 57 | public function publicConcreteToConcrete() {} |
||
| 58 | public abstract function publicAbstractToAbstract() {} |
||
| 59 | |||
| 60 | protected function protectedConcreteToAbstract() {} |
||
| 61 | protected abstract function protectedAbstractToConcrete() {} |
||
| 62 | protected function protectedConcreteToConcrete() {} |
||
| 63 | protected abstract function protectedAbstractToAbstract() {} |
||
| 64 | |||
| 65 | private function privateConcreteToAbstract() {} |
||
| 66 | private abstract function privateAbstractToConcrete() {} |
||
| 67 | private function privateConcreteToConcrete() {} |
||
| 68 | private abstract function privateAbstractToAbstract() {} |
||
| 69 | } |
||
| 70 | PHP |
||
| 71 | , |
||
| 72 | $astLocator |
||
| 73 | ); |
||
| 74 | |||
| 75 | $toLocator = new StringSourceLocator( |
||
| 76 | <<<'PHP' |
||
| 77 | <?php |
||
| 78 | |||
| 79 | abstract class TheClass { |
||
| 80 | public abstract function publicConcreteToAbstract() {} |
||
| 81 | public function publicAbstractToConcrete() {} |
||
| 82 | public function publicConcreteToConcrete() {} |
||
| 83 | public abstract function publicAbstractToAbstract() {} |
||
| 84 | |||
| 85 | protected abstract function protectedConcreteToAbstract() {} |
||
| 86 | protected function protectedAbstractToConcrete() {} |
||
| 87 | protected function protectedConcreteToConcrete() {} |
||
| 88 | protected abstract function protectedAbstractToAbstract() {} |
||
| 89 | |||
| 90 | private abstract function privateConcreteToAbstract() {} |
||
| 91 | private function privateAbstractToConcrete() {} |
||
| 92 | private function privateConcreteToConcrete() {} |
||
| 93 | private abstract function privateAbstractToAbstract() {} |
||
| 94 | } |
||
| 95 | PHP |
||
| 96 | , |
||
| 97 | $astLocator |
||
| 98 | ); |
||
| 99 | |||
| 100 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 101 | $toClassReflector = new ClassReflector($toLocator); |
||
| 102 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
| 103 | $toClass = $toClassReflector->reflect('TheClass'); |
||
| 104 | |||
| 105 | $properties = [ |
||
| 106 | 'publicConcreteToAbstract' => ['[BC] CHANGED: Method publicConcreteToAbstract() of class TheClass changed from concrete to abstract'], |
||
| 107 | 'publicAbstractToConcrete' => [], |
||
| 108 | 'publicConcreteToConcrete' => [], |
||
| 109 | 'publicAbstractToAbstract' => [], |
||
| 110 | |||
| 111 | 'protectedConcreteToAbstract' => ['[BC] CHANGED: Method protectedConcreteToAbstract() of class TheClass changed from concrete to abstract'], |
||
| 112 | 'protectedAbstractToConcrete' => [], |
||
| 113 | 'protectedConcreteToConcrete' => [], |
||
| 114 | 'protectedAbstractToAbstract' => [], |
||
| 115 | |||
| 116 | 'privateConcreteToAbstract' => ['[BC] CHANGED: Method privateConcreteToAbstract() of class TheClass changed from concrete to abstract'], |
||
| 117 | 'privateAbstractToConcrete' => [], |
||
| 118 | 'privateConcreteToConcrete' => [], |
||
| 119 | 'privateAbstractToAbstract' => [], |
||
| 120 | ]; |
||
| 121 | |||
| 122 | return array_combine( |
||
| 123 | array_keys($properties), |
||
| 124 | array_map( |
||
| 125 | function (string $methodName, array $errorMessages) use ($fromClass, $toClass) : array { |
||
| 126 | return [ |
||
| 127 | $fromClass->getMethod($methodName), |
||
| 128 | $toClass->getMethod($methodName), |
||
| 129 | $errorMessages, |
||
| 130 | ]; |
||
| 131 | }, |
||
| 132 | array_keys($properties), |
||
| 133 | $properties |
||
| 134 | ) |
||
| 138 |