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

ConstantChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getName() 0 4 1
A doCheck() 0 14 3
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