EntryPointLookupProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 54
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntryPointLookup() 0 16 3
A __construct() 0 7 2
A add() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\WebpackEncoreBundle\EntryPoint;
6
7
use Nette;
8
use SixtyEightPublishers;
9
10 1
final class EntryPointLookupProvider implements IEntryPointLookupProvider
11
{
12 1
	use Nette\SmartObject;
13
14
	/** @var \SixtyEightPublishers\WebpackEncoreBundle\EntryPoint\IEntryPointLookup[] */
15
	private $lookups = [];
16
17
	/** @var string|NULL  */
18
	private $defaultName;
19
20
	/**
21
	 * @param \SixtyEightPublishers\WebpackEncoreBundle\EntryPoint\IEntryPointLookup[] $lookups
22
	 * @param string|null                                                              $defaultName
23
	 */
24
	public function __construct(array $lookups, ?string $defaultName = NULL)
25
	{
26 1
		foreach ($lookups as $lookup) {
27 1
			$this->add($lookup);
28
		}
29
30 1
		$this->defaultName = $defaultName;
31 1
	}
32
33
	/**
34
	 * @param \SixtyEightPublishers\WebpackEncoreBundle\EntryPoint\IEntryPointLookup $lookup
35
	 *
36
	 * @return void
37
	 */
38
	private function add(IEntryPointLookup $lookup): void
39
	{
40 1
		$this->lookups[$lookup->getBuildName()] = $lookup;
41 1
	}
42
43
	/************** interface \SixtyEightPublishers\WebpackEncoreBundle\EntryPoint\IEntryPointLookupProvider **************/
44
45
	/**
46
	 * {@inheritdoc}
47
	 */
48
	public function getEntryPointLookup(string $buildName = NULL): IEntryPointLookup
49
	{
50 1
		$buildName = $buildName ?? $this->defaultName;
51
52 1
		if (NULL === $buildName) {
53 1
			throw new SixtyEightPublishers\WebpackEncoreBundle\Exception\EntryPointNotFoundException('There is no default build configured: please pass an argument to getEntryPointLookup().');
54
		}
55
56 1
		if (!isset($this->lookups[$buildName])) {
57 1
			throw new SixtyEightPublishers\WebpackEncoreBundle\Exception\EntryPointNotFoundException(sprintf(
58 1
				'The build "%s" is not configured.',
59 1
				$buildName
60
			));
61
		}
62
63 1
		return $this->lookups[$buildName];
64
	}
65
}
66