| Conditions | 10 |
| Paths | 64 |
| Total Lines | 58 |
| Code Lines | 36 |
| 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 |
||
| 120 | public function testChildElementsCollection(): void |
||
| 121 | { |
||
| 122 | $flightPartnerRefs = $this->flightPartnerRefCollection->get($this->tweety); |
||
| 123 | |||
| 124 | $daisyRef = $flightPartnerRefs[0]; |
||
| 125 | $pluckyRef = $flightPartnerRefs[1]; |
||
| 126 | |||
| 127 | $this->assertEquals($this->daisy->getId(), $daisyRef->getTextContent()); |
||
| 128 | $this->assertEquals($this->plucky->getId(), $pluckyRef->getTextContent()); |
||
| 129 | |||
| 130 | $birdoRef = $this->modelInstance->newInstance(FlightPartnerRef::class); |
||
| 131 | $birdoRef->setTextContent($this->birdo->getId()); |
||
| 132 | |||
| 133 | $flightPartners = [$birdoRef, $daisyRef, $pluckyRef]; |
||
| 134 | |||
| 135 | // directly test collection methods and not use the appropriate assertion methods |
||
| 136 | $this->assertCount(2, $flightPartnerRefs); |
||
| 137 | $this->flightPartnerRefCollection->add($this->tweety, $birdoRef); |
||
| 138 | |||
| 139 | $flightPartnerRefs = $this->flightPartnerRefCollection->get($this->tweety); |
||
| 140 | $this->assertCount(3, $flightPartnerRefs); |
||
| 141 | |||
| 142 | foreach ($flightPartners as $partner) { |
||
| 143 | $exists = false; |
||
| 144 | foreach ($this->flightPartnerRefCollection->get($this->tweety) as $ref) { |
||
| 145 | if ($ref->equals($partner)) { |
||
| 146 | $exists = true; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | $this->assertTrue($exists); |
||
| 150 | } |
||
| 151 | |||
| 152 | $this->flightPartnerRefCollection->remove($this->tweety, $daisyRef); |
||
| 153 | $flightPartnerRefs = $this->flightPartnerRefCollection->get($this->tweety); |
||
| 154 | $this->assertCount(2, $flightPartnerRefs); |
||
| 155 | foreach ([$birdoRef, $pluckyRef] as $partner) { |
||
| 156 | $exists = false; |
||
| 157 | foreach ($this->flightPartnerRefCollection->get($this->tweety) as $ref) { |
||
| 158 | if ($ref->equals($partner)) { |
||
| 159 | $exists = true; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | $this->assertTrue($exists); |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->flightPartnerRefCollection->addAll($this->tweety, $flightPartners); |
||
| 166 | foreach ([$birdoRef, $daisyRef, $pluckyRef] as $partner) { |
||
| 167 | $exists = false; |
||
| 168 | foreach ($this->flightPartnerRefCollection->get($this->tweety) as $ref) { |
||
| 169 | if ($ref->equals($partner)) { |
||
| 170 | $exists = true; |
||
| 171 | } |
||
| 172 | } |
||
| 173 | $this->assertTrue($exists); |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->flightPartnerRefCollection->clear($this->tweety); |
||
| 177 | $this->assertEmpty($this->flightPartnerRefCollection->get($this->tweety)); |
||
| 178 | } |
||
| 180 |