| Conditions | 1 |
| Paths | 1 |
| Total Lines | 94 |
| Code Lines | 42 |
| 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 const publicNullToNull = null; |
||
| 56 | public const publicValueChanged = 1; |
||
| 57 | public const publicValueToSimilarValue = '1'; |
||
| 58 | public const publicExpressionToExpressionValue = 101 + 5; |
||
| 59 | |||
| 60 | protected const protectedNullToNull = null; |
||
| 61 | protected const protectedValueChanged = 1; |
||
| 62 | protected const protectedValueToSimilarValue = '1'; |
||
| 63 | protected const protectedExpressionToExpressionValue = 101 + 5; |
||
| 64 | |||
| 65 | private const privateNullToNull = null; |
||
| 66 | private const privateValueChanged = 1; |
||
| 67 | private const privateValueToSimilarValue = '1'; |
||
| 68 | private const privateExpressionToExpressionValue = 101 + 5; |
||
| 69 | } |
||
| 70 | PHP |
||
| 71 | , |
||
| 72 | $astLocator |
||
| 73 | ); |
||
| 74 | |||
| 75 | $toLocator = new StringSourceLocator( |
||
| 76 | <<<'PHP' |
||
| 77 | <?php |
||
| 78 | |||
| 79 | class TheClass { |
||
| 80 | public const publicNullToNull = null; |
||
| 81 | public const publicValueChanged = 2; |
||
| 82 | public const publicValueToSimilarValue = 1; |
||
| 83 | public const publicExpressionToExpressionValue = 106; |
||
| 84 | |||
| 85 | protected const protectedNullToNull = null; |
||
| 86 | protected const protectedValueChanged = 2; |
||
| 87 | protected const protectedValueToSimilarValue = 1; |
||
| 88 | protected const protectedExpressionToExpressionValue = 106; |
||
| 89 | |||
| 90 | private const privateNullToNull = null; |
||
| 91 | private const privateValueChanged = 2; |
||
| 92 | private const privateValueToSimilarValue = 1; |
||
| 93 | private const privateExpressionToExpressionValue = 106; |
||
| 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 | 'publicNullToNull' => [], |
||
| 107 | 'publicValueChanged' => [ |
||
| 108 | '[BC] CHANGED: Value of constant TheClass::publicValueChanged changed from 1 to 2', |
||
| 109 | ], |
||
| 110 | 'publicValueToSimilarValue' => [ |
||
| 111 | '[BC] CHANGED: Value of constant TheClass::publicValueToSimilarValue changed from \'1\' to 1', |
||
| 112 | ], |
||
| 113 | 'publicExpressionToExpressionValue' => [], |
||
| 114 | 'protectedNullToNull' => [], |
||
| 115 | 'protectedValueChanged' => [ |
||
| 116 | '[BC] CHANGED: Value of constant TheClass::protectedValueChanged changed from 1 to 2', |
||
| 117 | ], |
||
| 118 | 'protectedValueToSimilarValue' => [ |
||
| 119 | '[BC] CHANGED: Value of constant TheClass::protectedValueToSimilarValue changed from \'1\' to 1', |
||
| 120 | ], |
||
| 121 | 'protectedExpressionToExpressionValue' => [], |
||
| 122 | 'privateNullToNull' => [], |
||
| 123 | 'privateValueChanged' => [], |
||
| 124 | 'privateValueToSimilarValue' => [], |
||
| 125 | 'privateExpressionToExpressionValue' => [], |
||
| 126 | ]; |
||
| 127 | |||
| 128 | return array_combine( |
||
| 129 | array_keys($properties), |
||
| 130 | array_map( |
||
| 131 | function (string $constant, array $errorMessages) use ($fromClass, $toClass) : array { |
||
| 132 | return [ |
||
| 133 | $fromClass->getReflectionConstant($constant), |
||
| 134 | $toClass->getReflectionConstant($constant), |
||
| 135 | $errorMessages, |
||
| 136 | ]; |
||
| 137 | }, |
||
| 138 | array_keys($properties), |
||
| 139 | $properties |
||
| 140 | ) |
||
| 144 |