PriceCalculatorExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigSchema() 0 4 1
A loadConfiguration() 0 6 1
A register() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace Sunfox\PriceCalculator\DI;
4
5
use Nette\Configurator;
6
use Nette\DI\Compiler;
7
use Nette\DI\CompilerExtension;
8
use Nette\Schema\Expect;
9
use Nette\Schema\Schema;
10
use Sunfox\PriceCalculator\PriceCalculator;
11 1
use Sunfox\PriceCalculator\PriceCalculatorFactory;
12
13
final class PriceCalculatorExtension extends CompilerExtension
14
{
15
	public function getConfigSchema(): Schema
16
	{
17
		return Expect::structure([
18
			'calculatorClass' => Expect::string(PriceCalculator::class),
19
		]);
20
	}
21
22 1
	public function loadConfiguration(): void
23 1
	{
24
		$builder = $this->getContainerBuilder();
25 1
26 1
		$builder->addDefinition($this->prefix('factory'))
27 1
			->setFactory(PriceCalculatorFactory::class, [$this->config->calculatorClass]);
28
	}
29 1
30
	public static function register(Configurator $config): void
31 1
	{
32 1
		$config->onCompile[] = function (Configurator $config, Compiler $compiler): void {
33 1
			$compiler->addExtension('priceCalculator', new self);
34 1
		};
35
	}
36
}
37