Passed
Push — master ( d75fe6...8137a1 )
by Tomáš
07:51
created

PriceCalculatorExtension::getConfigSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
b 0
f 0
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