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