| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| 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 |
||
| 70 | public function testAliasedItemProperty() |
||
| 71 | { |
||
| 72 | $itemFactory = new ItemFactory(0); |
||
| 73 | $rawItem = (object)[ |
||
| 74 | 'type' => ['test'], |
||
| 75 | 'properties' => [ |
||
| 76 | (object)[ |
||
| 77 | 'name' => 'alias-property', |
||
| 78 | 'profile' => MicroformatsFactory::MF2_PROFILE_URI, |
||
| 79 | 'values' => ['value'] |
||
| 80 | ] |
||
| 81 | ], |
||
| 82 | 'children' => [ |
||
| 83 | (object)[ |
||
| 84 | 'type' => ['test'] |
||
| 85 | ] |
||
| 86 | ] |
||
| 87 | ]; |
||
| 88 | $item = $itemFactory($rawItem); |
||
| 89 | $this->assertInstanceOf(Item::class, $item); |
||
| 90 | $this->assertEquals( |
||
| 91 | [MicroformatsFactory::MF2_PROFILE_URI.'alias-property' => [new StringValue('value')]], |
||
| 92 | $item->getProperties()->export() |
||
| 93 | ); |
||
| 94 | $propertyList = $item->getProperties(); |
||
| 95 | $this->assertTrue( |
||
| 96 | $propertyList->offsetExists( |
||
| 97 | (object)['name' => 'alias-property', 'profile' => MicroformatsFactory::MF2_PROFILE_URI] |
||
| 98 | ) |
||
| 99 | ); |
||
| 100 | /** @noinspection PhpIllegalArrayKeyTypeInspection */ |
||
| 101 | $this->assertTrue( |
||
| 102 | isset( |
||
| 103 | $propertyList[(object)['name' => 'alias-property', 'profile' => MicroformatsFactory::MF2_PROFILE_URI]] |
||
| 104 | ) |
||
| 105 | ); |
||
| 106 | $this->assertTrue( |
||
| 107 | $propertyList->offsetExists( |
||
| 108 | (object)['name' => 'aliasProperty', 'profile' => MicroformatsFactory::MF2_PROFILE_URI] |
||
| 109 | ) |
||
| 110 | ); |
||
| 111 | $this->assertTrue( |
||
| 112 | $propertyList->offsetExists('alias-property') |
||
| 113 | ); |
||
| 114 | $this->assertFalse( |
||
| 115 | $propertyList->offsetExists('invalid-alias-property') |
||
| 116 | ); |
||
| 117 | $this->assertEquals( |
||
| 118 | (object)[ |
||
| 119 | 'format' => 0, |
||
| 120 | 'id' => null, |
||
| 121 | 'language' => null, |
||
| 122 | 'types' => ['test'], |
||
| 123 | 'properties' => [ |
||
| 124 | MicroformatsFactory::MF2_PROFILE_URI.'alias-property' => ['value'] |
||
| 125 | ], |
||
| 126 | 'items' => [ |
||
| 127 | (object)[ |
||
| 128 | 'format' => 0, |
||
| 129 | 'id' => null, |
||
| 130 | 'language' => null, |
||
| 131 | 'types' => ['test'], |
||
| 132 | 'properties' => [], |
||
| 133 | 'items' => [], |
||
| 134 | 'value' => null |
||
| 135 | ] |
||
| 136 | ], |
||
| 137 | 'value' => null |
||
| 138 | ], |
||
| 139 | $item->export() |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | |||
| 197 |