Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
142 | public function testHydrateHalItem() |
||
143 | { |
||
144 | $orderMetadata = new ClassMetadata( |
||
145 | 'order', |
||
146 | 'Mapado\RestClientSdk\Tests\Model\Hal\Order', |
||
147 | 'Mapado\RestClientSdk\Tests\Model\JsonLd\ModelRepository' |
||
148 | ); |
||
149 | $orderMetadata->setAttributeList([ |
||
150 | new Attribute('_links.self.href', 'id', 'string', true), |
||
151 | new Attribute('total', 'total', 'float'), |
||
152 | new Attribute('currency', 'currency', 'string'), |
||
153 | new Attribute('status', 'status', 'string'), |
||
154 | ]); |
||
155 | |||
156 | $mapping = new Mapping(); |
||
157 | $mapping->setConfig([ |
||
158 | 'collectionKey' => '_embedded.ea:order', |
||
159 | ]); |
||
160 | $mapping->setMapping([ $orderMetadata ]); |
||
161 | |||
162 | $this->mockGenerator->orphanize('__construct'); |
||
163 | $this->mockGenerator->shuntParentClassCalls(); |
||
164 | $sdk = new \mock\Mapado\RestClientSdk\SdkClient; |
||
165 | $this->calling($sdk)->getMapping = $mapping; |
||
166 | $this->calling($sdk)->getSerializer = new Serializer($mapping); |
||
167 | |||
168 | $this |
||
169 | ->given($this->newTestedInstance($sdk)) |
||
170 | // test one hal entity |
||
171 | ->and($orderArray = json_decode(file_get_contents(__DIR__ . '/../../data/order.hal.json'), true)) |
||
172 | ->then |
||
173 | ->object($order = $this->testedInstance->hydrate($orderArray, 'Mapado\RestClientSdk\Tests\Model\Hal\Order')) |
||
174 | ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\Hal\Order') |
||
175 | ->string($order->getStatus()) |
||
176 | ->isEqualTo('shipped') |
||
177 | ->string($order->getId()) |
||
178 | ->isEqualTo('/orders/123') |
||
179 | |||
180 | // test a json-ld list |
||
181 | ->and($orderListArray = json_decode(file_get_contents(__DIR__ . '/../../data/orderList.hal.json'), true)) |
||
182 | ->then |
||
183 | ->object($orderList = $this->testedInstance->hydrateList($orderListArray, 'Mapado\RestClientSdk\Tests\Model\Hal\Order')) |
||
184 | ->isInstanceOf('Mapado\RestClientSdk\Collection\HalCollection') |
||
185 | ->integer($orderList->getTotalItems()) |
||
186 | ->isEqualTo(2) |
||
187 | |||
188 | ->object($order = $orderList[0]) |
||
189 | ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\Hal\Order') |
||
190 | ->string($order->getId()) |
||
191 | ->isEqualTo('/orders/123') |
||
192 | ->string($orderList[1]->getId()) |
||
193 | ->isEqualTo('/orders/124') |
||
194 | ; |
||
195 | } |
||
196 | } |
||
197 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: