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