InPortalClassChecker   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
c 0
b 0
f 0
dl 0
loc 115
ccs 32
cts 32
cp 1
rs 10
wmc 17

8 Methods

Rating   Name   Duplication   Size   Complexity  
A paramToString() 0 15 3
A isEvent() 0 3 1
A ignoreScopeChange() 0 3 1
A getName() 0 3 1
A processMethod() 0 11 6
A isEventHandler() 0 5 2
A isTag() 0 6 2
A isTagProcessor() 0 3 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 2
	protected function processMethod()
40
	{
41 2
		if ( $this->isEventHandler() && ($this->isEvent() || $this->ignoreScopeChange()) ) {
42 2
			$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope'];
43
		}
44
45 2
		if ( $this->isTagProcessor() && $this->isTag() ) {
46 2
			$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope'];
47
		}
48
49 2
		parent::processMethod();
50 2
	}
51
52
	/**
53
	 * Builds string representation of a parameter.
54
	 *
55
	 * @param array $parameter_data Parameter data.
56
	 *
57
	 * @return string
58
	 */
59 2
	protected function paramToString(array $parameter_data)
60
	{
61 2
		$hash_part = parent::paramToString($parameter_data);
62
63 2
		if ( $this->isEventHandler() ) {
64 2
			$hash_part = str_replace('&$event', '$event', $hash_part);
65 2
			$hash_part = str_replace('\kEvent $event', '$event', $hash_part);
66 2
			$hash_part = str_replace('kEvent $event', '$event', $hash_part);
67
		}
68 2
		elseif ( $this->isTagProcessor() ) {
69 2
			$hash_part = str_replace('array $params', '$params', $hash_part);
70 2
			$hash_part = str_replace('$params', 'array $params', $hash_part);
71
		}
72
73 2
		return $hash_part;
74
	}
75
76
	/**
77
	 * Determines if current class is an event handler.
78
	 *
79
	 * @return boolean
80
	 */
81 2
	protected function isEventHandler()
82
	{
83 2
		$class_name = $this->sourceClassData['Name'];
84
85 2
		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 2
	protected function isTagProcessor()
94
	{
95 2
		return substr($this->sourceClassData['Name'], -12) === 'TagProcessor';
96
	}
97
98
	/**
99
	 * Determines if current method is an event.
100
	 *
101
	 * @return boolean
102
	 */
103 2
	protected function isEvent()
104
	{
105 2
		return substr($this->sourceMethodData['Name'], 0, 2) === 'On';
106
	}
107
108
	/**
109
	 * Determines if current method is tag.
110
	 *
111
	 * @return boolean
112
	 */
113 2
	protected function isTag()
114
	{
115 2
		$first_letter = substr($this->sourceMethodData['Name'], 0, 1);
116
117 2
		return $first_letter === strtoupper($first_letter)
118 2
			&& $this->sourceMethodData['ParameterSignature'] === 'array $params';
119
	}
120
121
	/**
122
	 * Determines if method scope change should be ignored.
123
	 *
124
	 * @return boolean
125
	 */
126 2
	protected function ignoreScopeChange()
127
	{
128 2
		return in_array($this->sourceMethodData['Name'], $this->ignoreScopeChangeMethods);
129
	}
130
131
}
132