Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
119 | public function testNestedTable() { |
||
120 | $parser = new Parser( |
||
121 | new TokenStream( |
||
122 | new InputStream( |
||
123 | '{ |
||
124 | foo = { |
||
125 | ["test"] = { |
||
126 | 1337, |
||
127 | "bar" |
||
128 | } |
||
129 | } |
||
130 | }' |
||
131 | ) |
||
132 | ) |
||
133 | ); |
||
134 | |||
135 | $node = $parser->parse(); |
||
136 | |||
137 | $this->assertEquals(TableASTNode::NAME, $node->getName()); |
||
138 | $this->assertInstanceOf(TableASTNode::class, $node); |
||
139 | |||
140 | $this->assertCount(1, $node->getEntries()); |
||
141 | $entry = $node->getEntries()[0]; |
||
142 | |||
143 | $this->assertTrue($entry->hasKey()); |
||
144 | $this->assertEquals(StringASTNode::NAME, $entry->getKey()->getName()); |
||
145 | $this->assertInstanceOf(StringASTNode::class, $entry->getKey()); |
||
146 | $this->assertEquals("foo", $entry->getKey()->getValue()); |
||
147 | |||
148 | $this->assertEquals(TableASTNode::NAME, $entry->getValue()->getName()); |
||
149 | $this->assertInstanceOf(TableASTNode::class, $entry->getValue()); |
||
150 | $this->assertCount(1, $entry->getValue()->getEntries()); |
||
151 | |||
152 | $nestedEntry = $entry->getValue()->getEntries()[0]; |
||
153 | |||
154 | $this->assertTrue($nestedEntry->hasKey()); |
||
155 | $this->assertEquals(StringASTNode::NAME, $nestedEntry->getKey()->getName()); |
||
156 | $this->assertInstanceOf(StringASTNode::class, $nestedEntry->getKey()); |
||
157 | $this->assertEquals("test", $nestedEntry->getKey()->getValue()); |
||
158 | |||
159 | $this->assertEquals(TableASTNode::NAME, $nestedEntry->getValue()->getName()); |
||
160 | $this->assertInstanceOf(TableASTNode::class, $nestedEntry->getValue()); |
||
161 | $this->assertCount(2, $nestedEntry->getValue()->getEntries()); |
||
162 | |||
163 | $nestedNestedEntry1 = $nestedEntry->getValue()->getEntries()[0]; |
||
164 | |||
165 | $this->assertFalse($nestedNestedEntry1->hasKey()); |
||
166 | |||
167 | $this->assertEquals(NumberASTNode::NAME, $nestedNestedEntry1->getValue()->getName()); |
||
168 | $this->assertInstanceOf(NumberASTNode::class, $nestedNestedEntry1->getValue()); |
||
169 | $this->assertEquals(1337, $nestedNestedEntry1->getValue()->getValue()); |
||
170 | |||
171 | $nestedNestedEntry2 = $nestedEntry->getValue()->getEntries()[1]; |
||
172 | |||
173 | $this->assertFalse($nestedNestedEntry2->hasKey()); |
||
174 | |||
175 | $this->assertEquals(StringASTNode::NAME, $nestedNestedEntry2->getValue()->getName()); |
||
176 | $this->assertInstanceOf(StringASTNode::class, $nestedNestedEntry2->getValue()); |
||
177 | $this->assertEquals("bar", $nestedNestedEntry2->getValue()->getValue()); |
||
178 | } |
||
179 | |||
209 | } |