Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
88 | public function testNestedTable() { |
||
89 | $parser = new LuaParser( |
||
90 | new LuaTokenStream( |
||
91 | new LuaInputStream( |
||
92 | '{ |
||
93 | foo = { |
||
94 | ["test"] = { |
||
95 | 1337, |
||
96 | "bar" |
||
97 | } |
||
98 | } |
||
99 | }' |
||
100 | ) |
||
101 | ) |
||
102 | ); |
||
103 | |||
104 | $node = $parser->parse(); |
||
105 | |||
106 | $this->assertEquals(TableASTNode::NAME, $node->getName()); |
||
107 | $this->assertInstanceOf(TableASTNode::class, $node); |
||
108 | |||
109 | $this->assertCount(1, $node->getEntries()); |
||
110 | $entry = $node->getEntries()[0]; |
||
111 | |||
112 | $this->assertTrue($entry->hasKey()); |
||
113 | $this->assertEquals(StringASTNode::NAME, $entry->getKey()->getName()); |
||
114 | $this->assertInstanceOf(StringASTNode::class, $entry->getKey()); |
||
115 | $this->assertEquals("foo", $entry->getKey()->getValue()); |
||
116 | |||
117 | $this->assertEquals(TableASTNode::NAME, $entry->getValue()->getName()); |
||
118 | $this->assertInstanceOf(TableASTNode::class, $entry->getValue()); |
||
119 | $this->assertCount(1, $entry->getValue()->getEntries()); |
||
120 | |||
121 | $nestedEntry = $entry->getValue()->getEntries()[0]; |
||
122 | |||
123 | $this->assertTrue($nestedEntry->hasKey()); |
||
124 | $this->assertEquals(StringASTNode::NAME, $nestedEntry->getKey()->getName()); |
||
125 | $this->assertInstanceOf(StringASTNode::class, $nestedEntry->getKey()); |
||
126 | $this->assertEquals("test", $nestedEntry->getKey()->getValue()); |
||
127 | |||
128 | $this->assertEquals(TableASTNode::NAME, $nestedEntry->getValue()->getName()); |
||
129 | $this->assertInstanceOf(TableASTNode::class, $nestedEntry->getValue()); |
||
130 | $this->assertCount(2, $nestedEntry->getValue()->getEntries()); |
||
131 | |||
132 | $nestedNestedEntry1 = $nestedEntry->getValue()->getEntries()[0]; |
||
133 | |||
134 | $this->assertFalse($nestedNestedEntry1->hasKey()); |
||
135 | |||
136 | $this->assertEquals(NumberASTNode::NAME, $nestedNestedEntry1->getValue()->getName()); |
||
137 | $this->assertInstanceOf(NumberASTNode::class, $nestedNestedEntry1->getValue()); |
||
138 | $this->assertEquals(1337, $nestedNestedEntry1->getValue()->getValue()); |
||
139 | |||
140 | $nestedNestedEntry2 = $nestedEntry->getValue()->getEntries()[1]; |
||
141 | |||
142 | $this->assertFalse($nestedNestedEntry2->hasKey()); |
||
143 | |||
144 | $this->assertEquals(StringASTNode::NAME, $nestedNestedEntry2->getValue()->getName()); |
||
145 | $this->assertInstanceOf(StringASTNode::class, $nestedNestedEntry2->getValue()); |
||
146 | $this->assertEquals("bar", $nestedNestedEntry2->getValue()->getValue()); |
||
147 | } |
||
148 | |||
157 | } |