| Conditions | 2 |
| Total Lines | 96 |
| 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 |
||
| 184 | protected function reference(string $target, array $keys, array $expect, $value): void |
||
| 185 | { |
||
| 186 | $rc = new class ($keys, $expect, $value) implements BuildListener { |
||
| 187 | private $keys; |
||
| 188 | private $expectSame; |
||
| 189 | private $value; |
||
| 190 | private $calls = 0; |
||
| 191 | private $error; |
||
| 192 | |||
| 193 | public function __construct(array $keys, array $expectSame, $value) |
||
| 194 | { |
||
| 195 | $this->keys = $keys; |
||
| 196 | $this->expectSame = $expectSame; |
||
| 197 | $this->value = $value; |
||
| 198 | } |
||
| 199 | |||
| 200 | public function buildStarted(BuildEvent $event) |
||
| 201 | { |
||
| 202 | } |
||
| 203 | |||
| 204 | public function buildFinished(BuildEvent $event) |
||
| 205 | { |
||
| 206 | } |
||
| 207 | |||
| 208 | public function targetFinished(BuildEvent $event) |
||
| 209 | { |
||
| 210 | } |
||
| 211 | |||
| 212 | public function taskStarted(BuildEvent $event) |
||
| 213 | { |
||
| 214 | } |
||
| 215 | |||
| 216 | public function taskFinished(BuildEvent $event) |
||
| 217 | { |
||
| 218 | } |
||
| 219 | |||
| 220 | public function messageLogged(BuildEvent $event) |
||
| 221 | { |
||
| 222 | } |
||
| 223 | |||
| 224 | public function targetStarted(BuildEvent $event) |
||
| 225 | { |
||
| 226 | if ($event->getTarget()->getName() === '') { |
||
| 227 | return; |
||
| 228 | } |
||
| 229 | if ($this->error === null) { |
||
| 230 | try { |
||
| 231 | $msg = "Call " . $this->calls . " refid=\'" . $this->keys[$this->calls] . "\'"; |
||
| 232 | if ($this->value === null) { |
||
| 233 | $o = $event->getProject()->getReference($this->keys[$this->calls]); |
||
| 234 | if ($this->expectSame[$this->calls++]) { |
||
| 235 | PhingTaskTest::assertNull($o, $msg); |
||
| 236 | } else { |
||
| 237 | PhingTaskTest::assertNotNull($o, $msg); |
||
| 238 | } |
||
| 239 | } else { |
||
| 240 | // a rather convoluted equals() test |
||
| 241 | /** @var Path $expect */ |
||
| 242 | $expect = $this->value; |
||
| 243 | $received = $event->getProject()->getReference($this->keys[$this->calls]); |
||
| 244 | $shouldBeEqual = $this->expectSame[$this->calls++]; |
||
| 245 | if ($received === null) { |
||
| 246 | PhingTaskTest::assertFalse($shouldBeEqual, $msg); |
||
| 247 | } else { |
||
| 248 | $l1 = $expect->listPaths(); |
||
| 249 | $l2 = $received->listPaths(); |
||
| 250 | if (count($l1) === count($l2)) { |
||
| 251 | for ($i = 0, $iMax = count($l1); $i < $iMax; $i++) { |
||
| 252 | if ($l1[$i] !== $l2[$i]) { |
||
| 253 | PhingTaskTest::assertFalse($shouldBeEqual, $msg); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | PhingTaskTest::assertTrue($shouldBeEqual, $msg); |
||
| 257 | } else { |
||
| 258 | PhingTaskTest::assertFalse($shouldBeEqual, $msg); |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } catch (\Throwable $e) { |
||
| 263 | $this->error = $e; |
||
| 264 | } |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | public function getError() |
||
| 269 | { |
||
| 270 | return $this->error; |
||
| 271 | } |
||
| 272 | }; |
||
| 273 | $this->getProject()->addBuildListener($rc); |
||
| 274 | $this->getProject()->executeTarget($target); |
||
| 275 | $ae = $rc->getError(); |
||
| 276 | if ($ae !== null) { |
||
| 277 | throw $ae; |
||
| 278 | } |
||
| 279 | $this->getProject()->removeBuildListener($rc); |
||
| 280 | } |
||
| 282 |