Completed
Push — master ( 1e1aac...d6bf2c )
by C
05:36
created

ProcessLinksListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B onProcessLinksBefore() 0 22 4
1
<?php
2
namespace Tartana\Event\Listener;
3
use Tartana\Domain\Command\ProcessLinks;
4
use Tartana\Event\CommandEvent;
5
use Tartana\Mixins\HostFactoryAwareTrait;
6
7
class ProcessLinksListener
8
{
9
10
	use HostFactoryAwareTrait;
11
12 16
	public function onProcessLinksBefore (CommandEvent $event)
13
	{
14 16
		if (! $event->getCommand() instanceof ProcessLinks)
15
		{
16 14
			return;
17
		}
18
19 2
		$links = [];
20 2
		foreach ($event->getCommand()->getLinks() as $link)
21
		{
22 2
			$downloader = $this->getDownloader($link);
23 2
			if (empty($downloader))
24
			{
25 1
				$links[] = $link;
26 1
				continue;
27
			}
28
29 1
			$links = array_merge($links, $downloader->fetchLinkList($link));
30
		}
31
32 2
		$event->setCommand(new ProcessLinks(array_unique($links)));
33 2
	}
34
}
35