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

Extension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A beforeCompile() 6 19 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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