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