1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPSemVerChecker\Operation; |
4
|
|
|
|
5
|
|
|
use PhpParser\Node\Stmt; |
6
|
|
|
use PhpParser\Node\Stmt\ClassMethod; |
7
|
|
|
use PHPSemVerChecker\Node\Statement\ClassMethod as PClassMethod; |
8
|
|
|
|
9
|
|
|
abstract class ClassMethodOperationDelta extends Operation { |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $context; |
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
protected $visibility; |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $fileBefore; |
22
|
|
|
/** |
23
|
|
|
* @var Stmt |
24
|
|
|
*/ |
25
|
|
|
protected $contextBefore; |
26
|
|
|
/** |
27
|
|
|
* @var \PhpParser\Node\Stmt\ClassMethod |
28
|
|
|
*/ |
29
|
|
|
protected $classMethodBefore; |
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $fileAfter; |
34
|
|
|
/** |
35
|
|
|
* @var Stmt |
36
|
|
|
*/ |
37
|
|
|
protected $contextAfter; |
38
|
|
|
/** |
39
|
|
|
* @var \PhpParser\Node\Stmt\ClassMethod |
40
|
|
|
*/ |
41
|
|
|
protected $classMethodAfter; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $context |
45
|
|
|
* @param string $fileBefore |
46
|
|
|
* @param \PhpParser\Node\Stmt $contextBefore |
47
|
|
|
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodBefore |
48
|
|
|
* @param string $fileAfter |
49
|
|
|
* @param \PhpParser\Node\Stmt $contextAfter |
50
|
|
|
* @param \PhpParser\Node\Stmt\ClassMethod $classMethodAfter |
51
|
|
|
*/ |
52
|
|
|
public function __construct($context, |
53
|
|
|
$fileBefore, |
54
|
|
|
Stmt $contextBefore, |
55
|
|
|
ClassMethod $classMethodBefore, |
56
|
|
|
$fileAfter, |
57
|
|
|
Stmt $contextAfter, |
58
|
|
|
ClassMethod $classMethodAfter) |
59
|
|
|
{ |
60
|
|
|
$this->context = $context; |
61
|
|
|
$this->visibility = $this->getVisibility($classMethodAfter); |
62
|
|
|
$this->fileBefore = $fileBefore; |
63
|
|
|
$this->contextBefore = $contextBefore; |
64
|
|
|
$this->classMethodBefore = $classMethodBefore; |
65
|
|
|
$this->fileAfter = $fileAfter; |
66
|
|
|
$this->contextAfter = $contextAfter; |
67
|
|
|
$this->classMethodAfter = $classMethodAfter; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getLocation() |
74
|
|
|
{ |
75
|
|
|
return $this->fileAfter; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
|
|
public function getLine() |
82
|
|
|
{ |
83
|
|
|
return $this->classMethodAfter->getLine(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getTarget() |
90
|
|
|
{ |
91
|
|
|
return PClassMethod::getFullyQualifiedName($this->contextAfter, $this->classMethodAfter); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function getCode() |
98
|
|
|
{ |
99
|
|
|
return $this->code[$this->context][Visibility::get($this->visibility)]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getReason() |
106
|
|
|
{ |
107
|
|
|
return '[' . Visibility::toString($this->visibility) . '] ' . $this->reason; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
protected function getVisibility($context) |
114
|
|
|
{ |
115
|
|
|
return Visibility::getForContext($context); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|