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