| Conditions | 1 |
| Paths | 1 |
| Total Lines | 104 |
| Code Lines | 44 |
| 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 | class TheClass { |
||
| 55 | public $publicNothingToNothing; |
||
| 56 | public $publicNothingToNull; |
||
| 57 | public $publicNullToNull = null; |
||
| 58 | public $publicValueChanged = 1; |
||
| 59 | public $publicValueToSimilarValue = '1'; |
||
| 60 | public $publicExpressionToExpressionValue = 101 + 5; |
||
| 61 | |||
| 62 | protected $protectedNothingToNothing; |
||
| 63 | protected $protectedNothingToNull; |
||
| 64 | protected $protectedNullToNull = null; |
||
| 65 | protected $protectedValueChanged = 1; |
||
| 66 | protected $protectedValueToSimilarValue = '1'; |
||
| 67 | protected $protectedExpressionToExpressionValue = 101 + 5; |
||
| 68 | |||
| 69 | private $privateNothingToNothing; |
||
| 70 | private $privateNothingToNull; |
||
| 71 | private $privateNullToNull = null; |
||
| 72 | private $privateValueChanged = 1; |
||
| 73 | private $privateValueToSimilarValue = '1'; |
||
| 74 | private $privateExpressionToExpressionValue = 101 + 5; |
||
| 75 | } |
||
| 76 | PHP |
||
| 77 | , |
||
| 78 | $astLocator |
||
| 79 | ); |
||
| 80 | |||
| 81 | $toLocator = new StringSourceLocator( |
||
| 82 | <<<'PHP' |
||
| 83 | <?php |
||
| 84 | |||
| 85 | class TheClass { |
||
| 86 | public $publicNothingToNothing; |
||
| 87 | public $publicNothingToNull = null; |
||
| 88 | public $publicNullToNull = null; |
||
| 89 | public $publicValueChanged = 2; |
||
| 90 | public $publicValueToSimilarValue = 1; |
||
| 91 | public $publicExpressionToExpressionValue = 106; |
||
| 92 | |||
| 93 | protected $protectedNothingToNothing; |
||
| 94 | protected $protectedNothingToNull = null; |
||
| 95 | protected $protectedNullToNull = null; |
||
| 96 | protected $protectedValueChanged = 2; |
||
| 97 | protected $protectedValueToSimilarValue = 1; |
||
| 98 | protected $protectedExpressionToExpressionValue = 106; |
||
| 99 | |||
| 100 | private $privateNothingToNothing; |
||
| 101 | private $privateNothingToNull = null; |
||
| 102 | private $privateNullToNull = null; |
||
| 103 | private $privateValueChanged = 2; |
||
| 104 | private $privateValueToSimilarValue = 1; |
||
| 105 | private $privateExpressionToExpressionValue = 106; |
||
| 106 | } |
||
| 107 | PHP |
||
| 108 | , |
||
| 109 | $astLocator |
||
| 110 | ); |
||
| 111 | |||
| 112 | $fromClassReflector = new ClassReflector($fromLocator); |
||
| 113 | $toClassReflector = new ClassReflector($toLocator); |
||
| 114 | $fromClass = $fromClassReflector->reflect('TheClass'); |
||
| 115 | $toClass = $toClassReflector->reflect('TheClass'); |
||
| 116 | |||
| 117 | $properties = [ |
||
| 118 | 'publicNothingToNothing' => [], |
||
| 119 | 'publicNothingToNull' => [], |
||
| 120 | 'publicNullToNull' => [], |
||
| 121 | 'publicValueChanged' => ['[BC] CHANGED: Property TheClass#$publicValueChanged changed default value from 1 to 2'], |
||
| 122 | 'publicValueToSimilarValue' => ['[BC] CHANGED: Property TheClass#$publicValueToSimilarValue changed default value from \'1\' to 1'], |
||
| 123 | 'publicExpressionToExpressionValue' => [], |
||
| 124 | 'protectedNothingToNothing' => [], |
||
| 125 | 'protectedNothingToNull' => [], |
||
| 126 | 'protectedNullToNull' => [], |
||
| 127 | 'protectedValueChanged' => ['[BC] CHANGED: Property TheClass#$protectedValueChanged changed default value from 1 to 2'], |
||
| 128 | 'protectedValueToSimilarValue' => ['[BC] CHANGED: Property TheClass#$protectedValueToSimilarValue changed default value from \'1\' to 1'], |
||
| 129 | 'protectedExpressionToExpressionValue' => [], |
||
| 130 | 'privateNothingToNothing' => [], |
||
| 131 | 'privateNothingToNull' => [], |
||
| 132 | 'privateNullToNull' => [], |
||
| 133 | 'privateValueChanged' => ['[BC] CHANGED: Property TheClass#$privateValueChanged changed default value from 1 to 2'], |
||
| 134 | 'privateValueToSimilarValue' => ['[BC] CHANGED: Property TheClass#$privateValueToSimilarValue changed default value from \'1\' to 1'], |
||
| 135 | 'privateExpressionToExpressionValue' => [], |
||
| 136 | ]; |
||
| 137 | |||
| 138 | return array_combine( |
||
| 139 | array_keys($properties), |
||
| 140 | array_map( |
||
| 141 | function (string $property, array $errorMessages) use ($fromClass, $toClass) : array { |
||
| 142 | return [ |
||
| 143 | $fromClass->getProperty($property), |
||
| 144 | $toClass->getProperty($property), |
||
| 145 | $errorMessages, |
||
| 146 | ]; |
||
| 147 | }, |
||
| 148 | array_keys($properties), |
||
| 149 | $properties |
||
| 150 | ) |
||
| 154 |