CardPayExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 69
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 37 2
A beforeCompile() 0 18 4
1
<?php
2
3
namespace PaySys\CardPay\DI;
4
5
use Nette\DI\CompilerExtension;
6
use PaySys\CardPay\Configuration;
7
8
9
class CardPayExtension extends CompilerExtension
10
{
11
	const BASE_ROUTE = "CardPay:CardPay:process";
12
13
	/** @var array */
14
	private $defaults = [
15
		"mid" => "",
16
		"rurl" => self::BASE_ROUTE,
17
		"key" => "",
18
		"mode" => Configuration::PRODUCTION,
19
	];
20
21
	public function loadConfiguration()
22
	{
23
		$this->validateConfig($this->defaults);
0 ignored issues
show
Deprecated Code introduced by
The method Nette\DI\CompilerExtension::validateConfig() has been deprecated with message: use getConfigSchema()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
24
25
		$builder = $this->getContainerBuilder();
26
27
		$builder->addDefinition($this->prefix('config'))
28
			->setFactory('PaySys\CardPay\Configuration', [
29
				'mid' => $this->config['mid'],
30
				'rurl' => $this->config['rurl'],
31
				'key' => $this->config['key'],
32
			])
33
			->addSetup('setMode', [
34
				$this->config['mode'],
35
			]);
36
37
		if (method_exists($builder, 'addFactoryDefinition')) {
38
			$builder->addFactoryDefinition($this->prefix('button'))
39
				->setImplement('PaySys\CardPay\IButtonFactory')
40
				->getResultDefinition()
41
				->setFactory('PaySys\PaySys\Button', [
42
					'config' => $this->prefix('@config'),
43
				]);
44
		} else {
45
			$builder->addDefinition($this->prefix('button'))
0 ignored issues
show
Deprecated Code introduced by
The method Nette\DI\Definitions\Ser...inition::setImplement() has been deprecated with message: use $builder->addFactoryDefinition(...) or addAccessorDefinition(...)

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
				->setImplement('PaySys\CardPay\IButtonFactory')
0 ignored issues
show
Unused Code introduced by
The call to ServiceDefinition::setImplement() has too many arguments starting with 'PaySys\\CardPay\\IButtonFactory'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
47
				->setFactory('PaySys\PaySys\Button', [
48
					'config' => $this->prefix('@config'),
49
				]);
50
		}
51
52
		$builder->addDefinition($this->prefix('request'))
53
			->setFactory('PaySys\CardPay\Security\Request');
54
55
		$builder->addDefinition($this->prefix('response'))
56
			->setFactory('PaySys\CardPay\Security\Response');
57
	}
58
59
	public function beforeCompile()
60
	{
61
		$builder = $this->getContainerBuilder();
62
63
		if ($this->config['rurl'] === self::BASE_ROUTE) {
64
			if ($builder->hasDefinition('routing.router')) {
65
				$netteRouter = $builder->getDefinition('routing.router');
66
				$netteRouter->addSetup('$service->prepend(new Nette\Application\Routers\Route(\'cardpay-process\', ?));', [self::BASE_ROUTE]);
67
			}
68
69
			if ($builder->hasDefinition('nette.presenterFactory')) {
70
				$builder->getDefinition('nette.presenterFactory')
71
					->addSetup('setMapping', [
72
						['CardPay' => 'PaySys\CardPay\Application\UI\*Presenter'],
73
					]);
74
			}
75
		}
76
	}
77
}
78