Completed
Push — master ( 1857e6...d96bec )
by Joao
03:02
created

PropertyAnnotations::__construct()   C

Complexity

Conditions 9
Paths 22

Size

Total Lines 46
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 46
rs 5.0942
cc 9
eloc 27
nc 22
nop 4
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();
0 ignored issues
show
Unused Code introduced by
$propMeta is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The property getPropDontCreateNode does not seem to exist. Did you mean propDontCreateNode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
136
            if ($this->getPropName() == SerializerObject::OBJECT_ARRAY_IGNORE_NODE) {
137
                $this->getPropDontCreateNode = true;
0 ignored issues
show
Bug introduced by
The property getPropDontCreateNode does not seem to exist. Did you mean propDontCreateNode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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