ProcessLinksListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A onProcessLinksBefore() 0 19 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