| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 80 | 
| 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 | ||
| 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 const publicMaintainedPublic = 'value'; | ||
| 54 | public const publicReducedToProtected = 'value'; | ||
| 55 | public const publicReducedToPrivate = 'value'; | ||
| 56 | protected const protectedMaintainedProtected = 'value'; | ||
| 57 | protected const protectedReducedToPrivate = 'value'; | ||
| 58 | protected const protectedIncreasedToPublic = 'value'; | ||
| 59 | private const privateMaintainedPrivate = 'value'; | ||
| 60 | private const privateIncreasedToProtected = 'value'; | ||
| 61 | private const privateIncreasedToPublic = 'value'; | ||
| 62 | } | ||
| 63 | PHP | ||
| 64 | , | ||
| 65 | $astLocator | ||
| 66 | ); | ||
| 67 | |||
| 68 | $toLocator = new StringSourceLocator( | ||
| 69 | <<<'PHP' | ||
| 70 | <?php | ||
| 71 | |||
| 72 | class TheClass { | ||
| 73 | public const publicMaintainedPublic = 'value'; | ||
| 74 | protected const publicReducedToProtected = 'value'; | ||
| 75 | private const publicReducedToPrivate = 'value'; | ||
| 76 | protected const protectedMaintainedProtected = 'value'; | ||
| 77 | private const protectedReducedToPrivate = 'value'; | ||
| 78 | public const protectedIncreasedToPublic = 'value'; | ||
| 79 | private const privateMaintainedPrivate = 'value'; | ||
| 80 | protected const privateIncreasedToProtected = 'value'; | ||
| 81 | public const privateIncreasedToPublic = 'value'; | ||
| 82 | } | ||
| 83 | PHP | ||
| 84 | , | ||
| 85 | $astLocator | ||
| 86 | ); | ||
| 87 | |||
| 88 | $fromClassReflector = new ClassReflector($fromLocator); | ||
| 89 | $toClassReflector = new ClassReflector($toLocator); | ||
| 90 |         $fromClass          = $fromClassReflector->reflect('TheClass'); | ||
| 91 |         $toClass            = $toClassReflector->reflect('TheClass'); | ||
| 92 | |||
| 93 | $properties = [ | ||
| 94 | |||
| 95 | 'publicMaintainedPublic' => [], | ||
| 96 | 'publicReducedToProtected' => [ | ||
| 97 | '[BC] CHANGED: Constant TheClass::publicReducedToProtected visibility reduced from public to protected', | ||
| 98 | ], | ||
| 99 | 'publicReducedToPrivate' => [ | ||
| 100 | '[BC] CHANGED: Constant TheClass::publicReducedToPrivate visibility reduced from public to private', | ||
| 101 | ], | ||
| 102 | 'protectedMaintainedProtected' => [], | ||
| 103 | 'protectedReducedToPrivate' => [ | ||
| 104 | '[BC] CHANGED: Constant TheClass::protectedReducedToPrivate visibility reduced from protected to private', | ||
| 105 | ], | ||
| 106 | 'protectedIncreasedToPublic' => [], | ||
| 107 | 'privateMaintainedPrivate' => [], | ||
| 108 | 'privateIncreasedToProtected' => [], | ||
| 109 | 'privateIncreasedToPublic' => [], | ||
| 110 | ]; | ||
| 111 | |||
| 112 | return array_combine( | ||
| 113 | array_keys($properties), | ||
| 114 | array_map( | ||
| 115 |                 function (string $constant, array $errorMessages) use ($fromClass, $toClass) : array { | ||
| 116 | return [ | ||
| 117 | $fromClass->getReflectionConstant($constant), | ||
| 118 | $toClass->getReflectionConstant($constant), | ||
| 119 | $errorMessages, | ||
| 120 | ]; | ||
| 121 | }, | ||
| 122 | array_keys($properties), | ||
| 123 | $properties | ||
| 124 | ) | ||
| 128 |