ProcessLinksListener::onProcessLinksBefore()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 11
nc 4
nop 1
crap 4
1
<?php
2
namespace Tartana\Event\Listener;
3
4
use Tartana\Domain\Command\ProcessLinks;
5
use Tartana\Event\CommandEvent;
6
use Tartana\Mixins\HostFactoryAwareTrait;
7
8
class ProcessLinksListener
9
{
10
11
	use HostFactoryAwareTrait;
12
13 16
	public function onProcessLinksBefore(CommandEvent $event)
14
	{
15 16
		if (!$event->getCommand() instanceof ProcessLinks) {
16 14
			return;
17
		}
18
19 2
		$links = [];
20 2
		foreach ($event->getCommand()->getLinks() as $link) {
21 2
			$downloader = $this->getDownloader($link);
22 2
			if (empty($downloader)) {
23 1
				$links[] = $link;
24 1
				continue;
25
			}
26
27 1
			$links = array_merge($links, $downloader->fetchLinkList($link));
28
		}
29
30 2
		$event->setCommand(new ProcessLinks(array_unique($links)));
31 2
	}
32
}
33