|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpUnitGen\Model\PropertyTrait; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\Collection; |
|
6
|
|
|
use PhpUnitGen\Annotation\AnnotationInterface\AnnotationInterface; |
|
7
|
|
|
use PhpUnitGen\Annotation\ConstructorAnnotation; |
|
8
|
|
|
use PhpUnitGen\Annotation\GetterAnnotation; |
|
9
|
|
|
use PhpUnitGen\Annotation\SetterAnnotation; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Trait DocumentationTrait. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Paul Thébaud <[email protected]>. |
|
15
|
|
|
* @copyright 2017-2018 Paul Thébaud <[email protected]>. |
|
16
|
|
|
* @license https://opensource.org/licenses/MIT The MIT license. |
|
17
|
|
|
* @link https://github.com/paul-thebaud/phpunit-generator |
|
18
|
|
|
* @since Class available since Release 2.0.0. |
|
19
|
|
|
*/ |
|
20
|
|
|
trait DocumentationTrait |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string|null $documentation The documentation. |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $documentation; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Collection|AnnotationInterface[] $annotations The annotations contained in the documentation. |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $annotations; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string|null $documentation The new documentation to be set. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setDocumentation(?string $documentation): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->documentation = $documentation; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return string|null The current documentation. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getDocumentation(): ?string |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->documentation; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param AnnotationInterface $annotation The annotation to add. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function addAnnotation(AnnotationInterface $annotation): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->annotations->add($annotation); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return ConstructorAnnotation|null The constructor annotation, null if none. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getConstructorAnnotation(): ?ConstructorAnnotation |
|
60
|
|
|
{ |
|
61
|
|
|
$annotations = $this->annotations->filter(function (AnnotationInterface $annotation) { |
|
62
|
|
|
return $annotation->getType() === AnnotationInterface::TYPE_CONSTRUCTOR; |
|
63
|
|
|
}); |
|
64
|
|
|
if ($annotations->isEmpty()) { |
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
return $annotations->first(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return GetterAnnotation|null The getter annotation, null if none. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getGetterAnnotation(): ?GetterAnnotation |
|
74
|
|
|
{ |
|
75
|
|
|
$annotations = $this->annotations->filter(function (AnnotationInterface $annotation) { |
|
76
|
|
|
return $annotation->getType() === AnnotationInterface::TYPE_GETTER; |
|
77
|
|
|
}); |
|
78
|
|
|
if ($annotations->isEmpty()) { |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
return $annotations->first(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return SetterAnnotation|null The setter annotation, null if none. |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getSetterAnnotation(): ?SetterAnnotation |
|
88
|
|
|
{ |
|
89
|
|
|
$annotations = $this->annotations->filter(function (AnnotationInterface $annotation) { |
|
90
|
|
|
return $annotation->getType() === AnnotationInterface::TYPE_SETTER; |
|
91
|
|
|
}); |
|
92
|
|
|
if ($annotations->isEmpty()) { |
|
93
|
|
|
return null; |
|
94
|
|
|
} |
|
95
|
|
|
return $annotations->first(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return Collection|AnnotationInterface[] The mock annotations. |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getMockAnnotations(): Collection |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->annotations->filter(function (AnnotationInterface $annotation) { |
|
104
|
|
|
return $annotation->getType() === AnnotationInterface::TYPE_MOCK; |
|
105
|
|
|
}); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return Collection|AnnotationInterface[] The assertion annotations. |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getAssertAnnotations(): Collection |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->annotations->filter(function (AnnotationInterface $annotation) { |
|
114
|
|
|
return $annotation->getType() === AnnotationInterface::TYPE_ASSERT; |
|
115
|
|
|
}); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|