Completed
Push — master ( 0e1c32...e580ff )
by T
05:02
created

ClassMethodOperationUnary::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 ClassMethodOperationUnary 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 $file;
22
	/**
23
	 * @var \PhpParser\Node\Stmt
24
	 */
25
	protected $contextValue;
26
	/**
27
	 * @var \PhpParser\Node\Stmt\ClassMethod
28
	 */
29
	protected $classMethod;
30
31
	/**
32
	 * @param string                           $context
33
	 * @param string                           $file
34
	 * @param \PhpParser\Node\Stmt             $contextValue
35
	 * @param \PhpParser\Node\Stmt\ClassMethod $classMethod
36
	 */
37 56
	public function __construct($context, $file, Stmt $contextValue, ClassMethod $classMethod)
38
	{
39 56
		$this->context = $context;
40 56
		$this->visibility = $this->getVisibility($classMethod);
41 56
		$this->file = $file;
42 56
		$this->contextValue = $contextValue;
43 56
		$this->classMethod = $classMethod;
44 56
	}
45
46
	/**
47
	 * @return string
48
	 */
49
	public function getLocation()
50
	{
51
		return $this->file;
52
	}
53
54
	/**
55
	 * @return int
56
	 */
57
	public function getLine()
58
	{
59
		return $this->classMethod->getLine();
60
	}
61
62
	/**
63
	 * @return string
64
	 */
65 56
	public function getTarget()
66
	{
67 56
		return PClassMethod::getFullyQualifiedName($this->contextValue, $this->classMethod);
68
	}
69
70
	/**
71
	 * @return string
72
	 */
73 56
	public function getCode()
74
	{
75 56
		return $this->code[$this->context][Visibility::get($this->visibility)];
76
	}
77
78
	/**
79
	 * @return string
80
	 */
81 56
	public function getReason()
82
	{
83 56
		return '[' . Visibility::toString($this->visibility) . '] ' . $this->reason;
84
	}
85
86
	/**
87
	 * @return string
88
	 */
89 56
	protected function getVisibility($context)
90
	{
91 56
		return Visibility::getForContext($context);
92
	}
93
}
94