Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 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 |
||
37 | public function testSetGetHasForClassProperty() |
||
38 | { |
||
39 | $classDefinition = $this->getSimpleInstance(); |
||
40 | $this->assertFalse($classDefinition->hasProperty('test1')); |
||
41 | $this->assertFalse($classDefinition->hasProperty('test2')); |
||
42 | |||
43 | $property = new \PhpParser\Node\Stmt\Property( |
||
44 | 0, |
||
45 | array( |
||
46 | new \PhpParser\Node\Stmt\PropertyProperty( |
||
47 | 'test1', |
||
48 | new \PhpParser\Node\Scalar\String_( |
||
49 | 'test string' |
||
50 | ) |
||
51 | ) |
||
52 | ) |
||
53 | ); |
||
54 | $classDefinition->addProperty($property); |
||
55 | |||
56 | $this->assertTrue($classDefinition->hasProperty('test1')); |
||
57 | $this->assertFalse($classDefinition->hasProperty('test2')); |
||
58 | |||
59 | $property = new \PhpParser\Node\Stmt\Property( |
||
60 | 0, |
||
61 | array( |
||
62 | new \PhpParser\Node\Stmt\PropertyProperty( |
||
63 | 'test2', |
||
64 | new \PhpParser\Node\Scalar\String_( |
||
65 | 'test string' |
||
66 | ) |
||
67 | ) |
||
68 | ) |
||
69 | ); |
||
70 | $classDefinition->addProperty($property); |
||
71 | |||
72 | $this->assertTrue($classDefinition->hasProperty('test1')); |
||
73 | $this->assertTrue($classDefinition->hasProperty('test2')); |
||
74 | |||
75 | $property = new \PhpParser\Node\Stmt\Property(0, [ |
||
76 | new \PhpParser\Node\Stmt\PropertyProperty( |
||
77 | 'foo', |
||
78 | new \PhpParser\Node\Scalar\String_('test string') |
||
79 | ), |
||
80 | new \PhpParser\Node\Stmt\PropertyProperty( |
||
81 | 'bar', |
||
82 | new \PhpParser\Node\Scalar\String_('test string') |
||
83 | ) |
||
84 | ]); |
||
85 | $classDefinition->addProperty($property); |
||
86 | |||
87 | $this->assertTrue($classDefinition->hasProperty('foo')); |
||
88 | $this->assertTrue($classDefinition->hasProperty('bar')); |
||
89 | } |
||
90 | |||
150 |