Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 26 |
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 |
||
23 | public function testWillDetectChangesInProperties() : void |
||
24 | { |
||
25 | $astLocator = (new BetterReflection())->astLocator(); |
||
26 | |||
27 | $fromLocator = new StringSourceLocator( |
||
28 | <<<'PHP' |
||
29 | <?php |
||
30 | |||
31 | class TheClass { |
||
32 | public $a; |
||
33 | protected $b; |
||
34 | private $c; |
||
35 | public static $d; |
||
36 | public $G; |
||
37 | } |
||
38 | PHP |
||
39 | , |
||
40 | $astLocator |
||
41 | ); |
||
42 | |||
43 | $toLocator = new StringSourceLocator( |
||
44 | <<<'PHP' |
||
45 | <?php |
||
46 | |||
47 | class TheClass { |
||
48 | protected $b; |
||
49 | public static $d; |
||
50 | public $e; |
||
51 | public $f; |
||
52 | public $g; |
||
53 | } |
||
54 | PHP |
||
55 | , |
||
56 | $astLocator |
||
57 | ); |
||
58 | |||
59 | $comparator = $this->createMock(PropertyBased::class); |
||
60 | |||
61 | $comparator |
||
62 | ->expects(self::exactly(2)) |
||
63 | ->method('__invoke') |
||
64 | ->willReturnCallback(static function (ReflectionProperty $from, ReflectionProperty $to) : Changes { |
||
65 | $propertyName = $from->getName(); |
||
66 | |||
67 | self::assertSame($propertyName, $to->getName()); |
||
68 | |||
69 | return Changes::fromList(Change::added($propertyName, true)); |
||
70 | }); |
||
71 | |||
72 | Assertion::assertChangesEqual( |
||
73 | Changes::fromList( |
||
74 | Change::added('b', true), |
||
75 | Change::added('d', true) |
||
76 | ), |
||
77 | (new PropertyChanged($comparator))->__invoke( |
||
78 | (new ClassReflector($fromLocator))->reflect('TheClass'), |
||
79 | (new ClassReflector($toLocator))->reflect('TheClass') |
||
80 | ) |
||
171 |