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; |
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
|
|
|
public function getName() |
30
|
|
|
{ |
31
|
|
|
return 'inportal_class'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Processes method. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function processMethod() |
40
|
|
|
{ |
41
|
|
|
if ( $this->isEventHandler() && ($this->isEvent() || $this->ignoreScopeChange()) ) { |
42
|
|
|
$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ( $this->isTagProcessor() && ($this->sourceMethodData['ParameterSignature'] === 'array $params') ) { |
46
|
|
|
$this->targetMethodData['Scope'] = $this->sourceMethodData['Scope']; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
parent::processMethod(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Builds string representation of a parameter. |
54
|
|
|
* |
55
|
|
|
* @param array $parameter_data Parameter data. |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
protected function paramToString(array $parameter_data) |
60
|
|
|
{ |
61
|
|
|
$hash_part = parent::paramToString($parameter_data); |
62
|
|
|
|
63
|
|
|
if ( $this->isEventHandler() ) { |
64
|
|
|
$hash_part = str_replace('&$event', '$event', $hash_part); |
65
|
|
|
$hash_part = str_replace('\kEvent $event', '$event', $hash_part); |
66
|
|
|
$hash_part = str_replace('kEvent $event', '$event', $hash_part); |
67
|
|
|
} |
68
|
|
|
elseif ( $this->isTagProcessor() ) { |
69
|
|
|
$hash_part = str_replace('array $params', '$params', $hash_part); |
70
|
|
|
$hash_part = str_replace('$params', 'array $params', $hash_part); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $hash_part; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Determines if current class is an event handler. |
78
|
|
|
* |
79
|
|
|
* @return boolean |
80
|
|
|
*/ |
81
|
|
|
protected function isEventHandler() |
82
|
|
|
{ |
83
|
|
|
$class_name = $this->sourceClassData['Name']; |
84
|
|
|
|
85
|
|
|
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
|
|
|
protected function isTagProcessor() |
94
|
|
|
{ |
95
|
|
|
return substr($this->sourceClassData['Name'], -12) === 'TagProcessor'; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Determines if current method is an event. |
100
|
|
|
* |
101
|
|
|
* @return boolean |
102
|
|
|
*/ |
103
|
|
|
protected function isEvent() |
104
|
|
|
{ |
105
|
|
|
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
|
|
|
protected function ignoreScopeChange() |
114
|
|
|
{ |
115
|
|
|
return in_array($this->sourceMethodData['Name'], $this->ignoreScopeChangeMethods); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|