Completed
Push — master ( b6a2ec...b3bd8f )
by Alexander
01:55
created

ConstantChecker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the Code-Insight library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker;
12
13
14
use Doctrine\Common\Cache\CacheProvider;
15
16
class ConstantChecker extends AbstractChecker
17
{
18
19
	const TYPE_CONSTANT_DELETED = 'constant.deleted';
20
21
	/**
22
	 * Constructor.
23
	 *
24
	 * @param CacheProvider $cache Cache provider.
25
	 */
26 3
	public function __construct(CacheProvider $cache)
27
	{
28 3
		parent::__construct($cache);
29
30 3
		$this->typeSorting = array(
31 3
			self::TYPE_CONSTANT_DELETED => 1,
32
		);
33 3
	}
34
35
	/**
36
	 * Returns backwards compatibility checker name.
37
	 *
38
	 * @return string
39
	 */
40 1
	public function getName()
41
	{
42 1
		return 'constant';
43
	}
44
45
	/**
46
	 * Collects backwards compatibility violations.
47
	 *
48
	 * @return void
49
	 */
50 2
	protected function doCheck()
51
	{
52
		$sql = 'SELECT Name
53 2
				FROM Constants';
54 2
		$source_constants = $this->sourceDatabase->fetchCol($sql);
55 2
		$target_constants = $this->targetDatabase->fetchCol($sql);
56
57 2
		foreach ( $source_constants as $source_constant_name ) {
58 2
			if ( !in_array($source_constant_name, $target_constants) ) {
59 1
				$this->addIncident(self::TYPE_CONSTANT_DELETED, $source_constant_name);
60 1
				continue;
61
			}
62 2
		}
63 2
	}
64
65
}
66