TimestampableExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadConfiguration() 0 16 1
A validateConfigTypes() 0 6 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\Model\Timestampable\Timestampable;
14
use Knp\DoctrineBehaviors\ORM\Timestampable\TimestampableSubscriber;
15
use Nette\Utils\AssertionException;
16
use Nette\Utils\Validators;
17
18
19
final class TimestampableExtension extends AbstractBehaviorExtension
20
{
21
22
	/**
23
	 * @var array
24
	 */
25
	private $default = [
26
		'isRecursive' => TRUE,
27
		'trait' => Timestampable::class,
28
		'dbFieldType' => 'datetime',
29
	];
30
31
32 1
	public function loadConfiguration()
33
	{
34 1
		$config = $this->getConfig($this->default);
35 1
		$this->validateConfigTypes($config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by $this->getConfig($this->default) on line 34 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...
36 1
		$builder = $this->getContainerBuilder();
37
38 1
		$builder->addDefinition($this->prefix('listener'))
39 1
			->setClass(TimestampableSubscriber::class, [
40 1
				'@' . $this->getClassAnalyzer()->getClass(),
41 1
				$config['isRecursive'],
42 1
				$config['trait'],
43 1
				$config['dbFieldType'],
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, 'trait', 'type');
57 1
		Validators::assertField($config, 'dbFieldType', 'string');
58 1
	}
59
60
}
61