Completed
Push — master ( a173a0...69eb71 )
by Michal
07:38
created

Extension::beforeCompile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 6
Ratio 31.58 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 19
ccs 12
cts 12
cp 1
rs 9.4285
cc 3
eloc 12
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Webrouse\AssetMacro\DI;
4
5
use Nette\DI\CompilerExtension;
6
use Webrouse\AssetMacro\AssetMacro;
7
use Webrouse\AssetMacro\Exceptions\UnexpectedValueException;
8
9
class Extension extends CompilerExtension
10
{
11
12
	public $defaults = [
13
		'wwwDir' => '%wwwDir%',
14
		'versions' => AssetMacro::VERSIONS_AUTODETECT,
15
		'autodetectPaths' => [
16
			'busters.json',
17
			'versions.json',
18
			'rev-manifest.json',
19
		],
20
		'missingAsset' => 'exception', // exception, notice, or ignore
21
		'missingVersion' => 'ignore',  // exception, notice, or ignore
22
	];
23
24
	public function beforeCompile()
25
	{
26 1
		$config = $this->getContainerBuilder()->expand($this->validateConfig($this->defaults));
0 ignored issues
show
Deprecated Code introduced by
The method Nette\DI\ContainerBuilder::expand() has been deprecated.

This method has been deprecated.

Loading history...
27
28 1 View Code Duplication
		if (!in_array($config['missingAsset'], ['exception', 'notice', 'ignore'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29 1
			throw new UnexpectedValueException(sprintf("Unexpected value '%s' of '%s' configuration key. Allowed values: 'exception', 'notice', 'ignore'.", $config['missingAsset'], $this->prefix('missingAsset')));
30
		}
31 1 View Code Duplication
		if (!in_array($config['missingVersion'], ['exception', 'notice', 'ignore'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32 1
			throw new UnexpectedValueException(sprintf("Unexpected value '%s' of '%s' configuration key. Allowed values: 'exception', 'notice', 'ignore'.", $config['missingVersion'], $this->prefix('missingVersion')));
33
		}
34
35 1
		$builder = $this->getContainerBuilder();
36 1
		$builder->getDefinition('latte.latteFactory')
37 1
			->addSetup("?->addProvider(?, ?)", ['@self', AssetMacro::CONFIG_PROVIDER, $config])
38 1
			->addSetup("?->onCompile[] = function(\$engine) { " .
39 1
				AssetMacro::class . "::install(\$engine->getCompiler()); }",
40 1
				['@self']
41
			);
42 1
	}
43
44
}
45