| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 15 | public function test_normnode() |
||
| 16 | { |
||
| 17 | // empty node |
||
| 18 | $node = new Node('foo'); |
||
| 19 | $this->assertSame('foo', $node->getType()); |
||
| 20 | $this->assertSame(null, $node->getText()); |
||
| 21 | $this->assertJsonStringEqualsJsonString( |
||
| 22 | '{ |
||
| 23 | "type": "foo" |
||
| 24 | }', |
||
| 25 | json_encode($node) |
||
| 26 | ); |
||
| 27 | |||
| 28 | // add attributes |
||
| 29 | $node->attr('foo', 'bar'); |
||
| 30 | $node->attr('bar', 'bar'); |
||
| 31 | $node->attr('foo', 'foo'); |
||
| 32 | $this->assertSame('foo', $node->attr('foo')); |
||
| 33 | $this->assertSame('bar', $node->attr('bar')); |
||
| 34 | $this->assertJsonStringEqualsJsonString( |
||
| 35 | '{ |
||
| 36 | "type": "foo", |
||
| 37 | "attrs": { |
||
| 38 | "foo": "foo", |
||
| 39 | "bar": "bar" |
||
| 40 | } |
||
| 41 | }', |
||
| 42 | json_encode($node) |
||
| 43 | ); |
||
| 44 | |||
| 45 | // add child |
||
| 46 | $child = new Node('bar'); |
||
| 47 | $node->addChild($child); |
||
| 48 | $this->assertJsonStringEqualsJsonString( |
||
| 49 | '{ |
||
| 50 | "type": "foo", |
||
| 51 | "attrs": { |
||
| 52 | "foo": "foo", |
||
| 53 | "bar": "bar" |
||
| 54 | }, |
||
| 55 | "content": [ |
||
| 56 | { |
||
| 57 | "type": "bar" |
||
| 58 | } |
||
| 59 | ] |
||
| 60 | }', |
||
| 61 | json_encode($node) |
||
| 62 | ); |
||
| 63 | |||
| 64 | // set text |
||
| 65 | $this->expectException('\\RuntimeException'); |
||
| 66 | $node->setText('hallo'); |
||
| 67 | } |
||
| 122 |