Completed
Push — master ( 77231c...ff4f9b )
by Alexander
03:22
created

InPortalClassChecker   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 105
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
B processMethod() 0 12 6
A paramToString() 0 16 3
A isEventHandler() 0 6 2
A isTagProcessor() 0 4 1
A isEvent() 0 4 1
A ignoreScopeChange() 0 4 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
class InPortalClassChecker extends ClassChecker
15
{
16
17
	/**
18
	 * Methods for which scope change isn't a BC break.
19
	 *
20
	 * @var array
21
	 */
22
	protected $ignoreScopeChangeMethods = array('mapPermissions', 'SetCustomQuery');
23
24
	/**
25
	 * Returns backwards compatibility checker name.
26
	 *
27
	 * @return string
28
	 */
29 1
	public function getName()
30
	{
31 1
		return 'inportal_class';
32
	}
33
34
	/**
35
	 * Processes method.
36
	 *
37
	 * @return void
38
	 */
39 1
	protected function processMethod()
40
	{
41 1
		if ( $this->isEventHandler() && ($this->isEvent() || $this->ignoreScopeChange()) ) {
42 1
			$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope'];
43 1
		}
44
45 1
		if ( $this->isTagProcessor() && ($this->sourceMethodData['ParameterSignature'] === 'array $params') ) {
46 1
			$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope'];
47 1
		}
48
49 1
		parent::processMethod();
50 1
	}
51
52
	/**
53
	 * Builds string representation of a parameter.
54
	 *
55
	 * @param array $parameter_data Parameter data.
56
	 *
57
	 * @return string
58
	 */
59 1
	protected function paramToString(array $parameter_data)
60
	{
61 1
		$hash_part = parent::paramToString($parameter_data);
62
63 1
		if ( $this->isEventHandler() ) {
64 1
			$hash_part = str_replace('&$event', '$event', $hash_part);
65 1
			$hash_part = str_replace('\kEvent $event', '$event', $hash_part);
66 1
			$hash_part = str_replace('kEvent $event', '$event', $hash_part);
67 1
		}
68 1
		elseif ( $this->isTagProcessor() ) {
69 1
			$hash_part = str_replace('array $params', '$params', $hash_part);
70 1
			$hash_part = str_replace('$params', 'array $params', $hash_part);
71 1
		}
72
73 1
		return $hash_part;
74
	}
75
76
	/**
77
	 * Determines if current class is an event handler.
78
	 *
79
	 * @return boolean
80
	 */
81 1
	protected function isEventHandler()
82
	{
83 1
		$class_name = $this->sourceClassData['Name'];
84
85 1
		return substr($class_name, -12) === 'EventHandler' || $class_name === 'AdminEventsHandler';
86
	}
87
88
	/**
89
	 * Determines if current class is a tag processor.
90
	 *
91
	 * @return boolean
92
	 */
93 1
	protected function isTagProcessor()
94
	{
95 1
		return substr($this->sourceClassData['Name'], -12) === 'TagProcessor';
96
	}
97
98
	/**
99
	 * Determines if current method is an event.
100
	 *
101
	 * @return boolean
102
	 */
103 1
	protected function isEvent()
104
	{
105 1
		return substr($this->sourceMethodData['Name'], 0, 2) === 'On';
106
	}
107
108
	/**
109
	 * Determines if method scope change should be ignored.
110
	 *
111
	 * @return boolean
112
	 */
113 1
	protected function ignoreScopeChange()
114
	{
115 1
		return in_array($this->sourceMethodData['Name'], $this->ignoreScopeChangeMethods);
116
	}
117
118
}
119