|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DF\PHPCoverFish\Validator; |
|
4
|
|
|
|
|
5
|
|
|
use DF\PHPCoverFish\Common\CoverFishPHPUnitFile; |
|
6
|
|
|
use DF\PHPCoverFish\Validator\Base\BaseCoverFishValidator; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ValidatorClassName, validate that the annotated Class exists (Class) |
|
10
|
|
|
* |
|
11
|
|
|
* @package DF\PHPCoverFish |
|
12
|
|
|
* @author Patrick Paechnatz <[email protected]> |
|
13
|
|
|
* @copyright 2015 Patrick Paechnatz <[email protected]> |
|
14
|
|
|
* @license http://www.opensource.org/licenses/MIT |
|
15
|
|
|
* @link http://github.com/dunkelfrosch/phpcoverfish/tree |
|
16
|
|
|
* @since class available since Release 0.9.0 |
|
17
|
|
|
* @version 0.9.9 |
|
18
|
|
|
*/ |
|
19
|
|
|
class ValidatorClassName extends BaseCoverFishValidator |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @return array |
|
23
|
|
|
*/ |
|
24
|
|
|
private function execute() |
|
25
|
|
|
{ |
|
26
|
|
|
preg_match_all("/(?P<class>(^(([\\\\])|([A-Z]))([A-Za-z0-9_\\\\]+)$))/", $this->coversToken, $this->result, PREG_SET_ORDER); |
|
27
|
|
|
|
|
28
|
|
|
return $this->result; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function validate() |
|
35
|
|
|
{ |
|
36
|
|
|
return count($this->execute()) > 0; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return bool |
|
41
|
|
|
*/ |
|
42
|
|
|
public function validateResultKeys() |
|
43
|
|
|
{ |
|
44
|
|
|
return array_key_exists('class', $this->getResult()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param CoverFishPHPUnitFile $phpUnitFile |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getMapping(CoverFishPHPUnitFile $phpUnitFile) |
|
53
|
|
|
{ |
|
54
|
|
|
$class = $this->getResult()['class']; |
|
55
|
|
|
// fqn detected? fully qualified classNames will be used directly without any kind of counterCheck |
|
56
|
|
|
// against use statement(s) - otherwise classFQN will be taken from use statement directly. |
|
57
|
|
|
$classFQN = $this->coverFishHelper->getClassFromUse($class, $phpUnitFile->getUsedClasses()); |
|
58
|
|
|
if (true === $this->coverFishHelper->checkClassHasFQN($class)) { |
|
59
|
|
|
$classFQN = $class; |
|
60
|
|
|
$class = $this->coverFishHelper->getClassNameFromClassFQN($classFQN); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$mappingOptions = array( |
|
64
|
|
|
'coverToken' => $this->coversToken, |
|
65
|
|
|
'coverMethod' => null, |
|
66
|
|
|
'coverAccessor' => null, |
|
67
|
|
|
'coverClass' => $class, |
|
68
|
|
|
'coverClassFQN' => $classFQN, |
|
69
|
|
|
'validatorMatch' => $this->getValidationTag(), |
|
70
|
|
|
'validatorClass' => get_class($this) |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
return $this->setMapping($mappingOptions); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getValidationInfo() |
|
80
|
|
|
{ |
|
81
|
|
|
return 'Specifies that the annotated class covers all methods in this class.'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getValidationTag() |
|
88
|
|
|
{ |
|
89
|
|
|
return 'ClassName'; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function __toString() |
|
96
|
|
|
{ |
|
97
|
|
|
return get_class($this); |
|
98
|
|
|
} |
|
99
|
|
|
} |