LoggableExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 41
c 0
b 0
f 0
wmc 2
lcom 1
cbo 4
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 17 1
A validateConfigTypes() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Zenify
7
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Zenify\DoctrineBehaviors\DI;
11
12
use Kdyby\Events\DI\EventsExtension;
13
use Knp\DoctrineBehaviors\ORM\Loggable\LoggableSubscriber;
14
use Nette\Utils\AssertionException;
15
use Nette\Utils\Validators;
16
use Zenify\DoctrineBehaviors\Loggable\LoggerCallable;
17
18
19
final class LoggableExtension extends AbstractBehaviorExtension
20
{
21
22
	/**
23
	 * @var array
24
	 */
25
	private $default = [
26
		'isRecursive' => TRUE,
27
		'loggerCallable' => LoggerCallable::class
28
	];
29
30
31 1
	public function loadConfiguration()
32
	{
33 1
		$config = $this->getConfig($this->default);
34 1
		$this->validateConfigTypes($config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->getConfig($this->default) on line 33 can also be of type string; however, Zenify\DoctrineBehaviors...::validateConfigTypes() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
35 1
		$builder = $this->getContainerBuilder();
36
37 1
		$loggerCallable = $this->buildDefinitionFromCallable($config['loggerCallable']);
38
39 1
		$builder->addDefinition($this->prefix('listener'))
40 1
			->setClass(LoggableSubscriber::class, [
41 1
				'@' . $this->getClassAnalyzer()->getClass(),
42 1
				$config['isRecursive'],
43 1
				'@' . $loggerCallable->getClass()
44
			])
45 1
			->setAutowired(FALSE)
46 1
			->addTag(EventsExtension::TAG_SUBSCRIBER);
47 1
	}
48
49
50
	/**
51
	 * @throws AssertionException
52
	 */
53 1
	private function validateConfigTypes(array $config)
54
	{
55 1
		Validators::assertField($config, 'isRecursive', 'bool');
56 1
		Validators::assertField($config, 'loggerCallable', 'type');
57 1
	}
58
59
}
60