1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByJG\AnyDataset\Model; |
4
|
|
|
|
5
|
|
|
use ReflectionProperty; |
6
|
|
|
|
7
|
|
|
class PropertyAnnotations extends Annotations |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
protected $propIgnore; |
11
|
|
|
protected $propName; |
12
|
|
|
protected $propAttributeOf; |
13
|
|
|
protected $propIsBlankNode; |
14
|
|
|
protected $propIsResourceUri; |
15
|
|
|
protected $propIsClassAttr; |
16
|
|
|
protected $propDontCreateNode; |
17
|
|
|
protected $propForceName; |
18
|
|
|
protected $propValue; |
19
|
|
|
|
20
|
|
|
protected $property; // Reflection objet |
21
|
|
|
protected $classAnnotation; |
22
|
|
|
|
23
|
|
|
public function __construct(ClassAnnotations $classAnnotation, $config, $property, $propertyName) |
24
|
|
|
{ |
25
|
|
|
$this->config = $config; |
26
|
|
|
$this->property = $property; |
27
|
|
|
$this->classAnnotation = $classAnnotation; |
28
|
|
|
|
29
|
|
|
$propMeta = array(); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->propName = ($property instanceof ReflectionProperty ? $property->getName() : $propertyName); |
32
|
|
|
$this->annotations = []; |
33
|
|
|
|
34
|
|
|
# Does nothing here |
35
|
|
|
if ($this->propName == "_propertyPattern" || $this->propName == "propertyPattern") { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$aux = [[]]; |
40
|
|
|
|
41
|
|
|
$this->propValue = null; |
42
|
|
|
|
43
|
|
|
# Determine where it located the Property Value --> Getter or inside the property |
44
|
|
|
if ($property instanceof ReflectionProperty && $property->isPublic()) { |
45
|
|
|
preg_match_all('/@(?<param>\S+)\s*(?<value>\S+)?\n/', $property->getDocComment(), $aux); |
46
|
|
|
$this->propValue = $property->getValue($this->classAnnotation->getClassInstance()); |
47
|
|
|
} else { |
48
|
|
|
// Remove Prefix "_" from Property Name to find a value |
49
|
|
|
if ($this->propName[0] == "_") { |
50
|
|
|
$this->propName = substr($this->propName, 1); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$methodName = $this->classAnnotation->getClassGetter() . ucfirst(preg_replace($this->classAnnotation->getClassPropertyPattern(0), |
54
|
|
|
$this->classAnnotation->getClassPropertyPattern(1), $this->propName)); |
55
|
|
|
|
56
|
|
|
if ($this->classAnnotation->getClassRefl()->hasMethod($methodName)) { |
57
|
|
|
$method = $this->classAnnotation->getClassRefl()->getMethod($methodName); |
58
|
|
|
preg_match_all('/@(?<param>\S+)\s*(?<value>\S+)?\r?\n/', $method->getDocComment(), $aux); |
59
|
|
|
$this->propValue = $method->invoke($this->classAnnotation->getClassInstance(), ""); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->annotations = $this->adjustParams($aux); |
64
|
|
|
$this->propName = $this->getAnnotations('nodename', $this->propName); |
65
|
|
|
if (strpos($this->propName, ":") === false) { |
66
|
|
|
$this->propName = $this->classAnnotation->getClassDefaultPrefix() . $this->propName; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPropName() |
71
|
|
|
{ |
72
|
|
|
return $this->propName; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getPropValue() |
76
|
|
|
{ |
77
|
|
|
return $this->propValue; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getPropIgnore() |
81
|
|
|
{ |
82
|
|
|
if (!$this->propIgnore) { |
83
|
|
|
$this->propIgnore = $this->getAnnotations("ignore", false); |
84
|
|
|
} |
85
|
|
|
return $this->propIgnore; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
View Code Duplication |
public function getPropAttributeOf() |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
if (!$this->propAttributeOf) { |
91
|
|
|
$this->propAttributeOf = ""; |
92
|
|
|
if (!$this->classAnnotation->getClassIsRDF()) { |
93
|
|
|
$this->propAttributeOf = $this->getAnnotations("isattributeof", ""); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
return $this->propAttributeOf; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
public function getPropIsBlankNode() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
if (!$this->propIsBlankNode) { |
102
|
|
|
$this->propIsBlankNode = ""; |
103
|
|
|
if ($this->classAnnotation->getClassIsRDF()) { |
104
|
|
|
$this->propIsBlankNode = $this->getAnnotations("isblanknode", ""); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
return $this->propIsBlankNode; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
View Code Duplication |
public function getPropIsResourceUri() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
if (!$this->propIsResourceUri) { |
113
|
|
|
$this->propIsResourceUri = false; |
114
|
|
|
if ($this->classAnnotation->getClassIsRDF()) { |
115
|
|
|
$this->propIsResourceUri = $this->getAnnotations("isresourceuri", false); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
return $this->propIsResourceUri; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
View Code Duplication |
public function getPropIsClassAttr() |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
if (!$this->propIsClassAttr) { |
124
|
|
|
$this->propIsClassAttr = false; |
125
|
|
|
if (!$this->classAnnotation->getClassIsRDF()) { |
126
|
|
|
$this->propIsClassAttr = $this->getAnnotations("isclassattr", false); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
return $this->propIsClassAttr; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getPropDontCreateNode() |
133
|
|
|
{ |
134
|
|
|
if (!$this->propDontCreateNode) { |
135
|
|
|
$this->getPropDontCreateNode = $this->getAnnotations("dontcreatenode", false); |
|
|
|
|
136
|
|
|
if ($this->getPropName() == SerializerObject::OBJECT_ARRAY_IGNORE_NODE) { |
137
|
|
|
$this->getPropDontCreateNode = true; |
|
|
|
|
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
return $this->propDontCreateNode; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function getPropForceName() |
144
|
|
|
{ |
145
|
|
|
if (!$this->propForceName) { |
146
|
|
|
$this->propForceName = $this->getAnnotations('dontcreatenode', ""); |
147
|
|
|
} |
148
|
|
|
return $this->propForceName; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.