This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Flying\Struct\Metadata; |
||
4 | |||
5 | /** |
||
6 | * Structure property metadata storage class |
||
7 | */ |
||
8 | class PropertyMetadata implements MetadataInterface |
||
9 | { |
||
10 | /** |
||
11 | * Hash for property object |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $hash; |
||
16 | /** |
||
17 | * Property name |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | private $name; |
||
22 | /** |
||
23 | * Class name for property object |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | private $class; |
||
28 | /** |
||
29 | * Configuration options for property object |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $config = []; |
||
34 | |||
35 | /** |
||
36 | * Class constructor |
||
37 | * |
||
38 | * @param string $name OPTIONAL Property name |
||
39 | * @param string $class OPTIONAL Class name for property object |
||
40 | * @param array $config OPTIONAL Configuration options for property object |
||
41 | * @throws \InvalidArgumentException |
||
42 | */ |
||
43 | 209 | public function __construct($name = null, $class = null, $config = null) |
|
44 | { |
||
45 | 209 | if ($name !== null) { |
|
46 | 186 | $this->setName($name); |
|
47 | 186 | } |
|
48 | 209 | if ($class !== null) { |
|
49 | 182 | $this->setClass($class); |
|
50 | 182 | } |
|
51 | 209 | if ($config !== null) { |
|
52 | 182 | $this->setConfig($config); |
|
53 | 182 | } |
|
54 | 209 | } |
|
55 | |||
56 | /** |
||
57 | * Defined by Serializable interface |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 17 | View Code Duplication | public function serialize() |
0 ignored issues
–
show
|
|||
62 | { |
||
63 | 17 | return serialize([ |
|
64 | 17 | 'name' => $this->getName(), |
|
65 | 17 | 'class' => $this->getClass(), |
|
66 | 17 | 'config' => $this->getConfig(), |
|
67 | 17 | ]); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Get property name |
||
72 | * |
||
73 | * @return mixed |
||
74 | */ |
||
75 | 200 | public function getName() |
|
76 | { |
||
77 | 200 | return $this->name; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Set property name |
||
82 | * |
||
83 | * @param string $name |
||
84 | * @throws \InvalidArgumentException |
||
85 | * @return $this |
||
86 | */ |
||
87 | 200 | View Code Duplication | public function setName($name) |
0 ignored issues
–
show
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. ![]() |
|||
88 | { |
||
89 | 200 | if ((!is_string($name)) && ($name !== null)) { |
|
90 | 2 | throw new \InvalidArgumentException('Property name must be a string'); |
|
91 | } |
||
92 | 198 | $this->name = $name; |
|
93 | 198 | $this->hash = null; |
|
94 | 198 | return $this; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Get class name for property object |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 196 | public function getClass() |
|
103 | { |
||
104 | 196 | return $this->class; |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Set class name for property object |
||
109 | * |
||
110 | * @param string $class |
||
111 | * @throws \InvalidArgumentException |
||
112 | * @return $this |
||
113 | */ |
||
114 | 202 | View Code Duplication | public function setClass($class) |
0 ignored issues
–
show
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. ![]() |
|||
115 | { |
||
116 | 202 | if ((!is_string($class)) && ($class !== null)) { |
|
117 | 2 | throw new \InvalidArgumentException('Property class name must be a string'); |
|
118 | } |
||
119 | 200 | $this->class = $class; |
|
120 | 200 | $this->hash = null; |
|
121 | 200 | return $this; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * Get configuration options for property object |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | 194 | public function getConfig() |
|
130 | { |
||
131 | 194 | return $this->config; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Set configuration options for property object |
||
136 | * |
||
137 | * @param array $config |
||
138 | * @return $this |
||
139 | */ |
||
140 | 196 | public function setConfig(array $config) |
|
141 | { |
||
142 | 196 | $this->config = $config; |
|
143 | 196 | $this->hash = null; |
|
144 | 196 | return $this; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * Defined by Serializable interface |
||
149 | * |
||
150 | * @param string $serialized |
||
151 | * @return void |
||
152 | * @throws \InvalidArgumentException |
||
153 | */ |
||
154 | 18 | public function unserialize($serialized) |
|
155 | { |
||
156 | 18 | $array = unserialize($serialized); |
|
157 | 18 | if (!is_array($array)) { |
|
158 | 1 | return; |
|
159 | } |
||
160 | 17 | if (array_key_exists('name', $array)) { |
|
161 | 17 | $this->setName($array['name']); |
|
162 | 17 | } |
|
163 | 17 | if (array_key_exists('class', $array)) { |
|
164 | 17 | $this->setClass($array['class']); |
|
165 | 17 | } |
|
166 | 17 | if (array_key_exists('config', $array)) { |
|
167 | 17 | $this->setConfig($array['config']); |
|
168 | 17 | } |
|
169 | 17 | } |
|
170 | |||
171 | /** |
||
172 | * Get metadata information as array |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | 14 | View Code Duplication | public function toArray() |
0 ignored issues
–
show
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. ![]() |
|||
177 | { |
||
178 | return [ |
||
179 | 14 | 'name' => $this->getName(), |
|
180 | 14 | 'class' => $this->getClass(), |
|
181 | 14 | 'config' => $this->getConfig(), |
|
182 | 14 | 'hash' => $this->getHash(), |
|
183 | 14 | ]; |
|
184 | } |
||
185 | |||
186 | /** |
||
187 | * Get hash for this structure metadata item |
||
188 | * |
||
189 | * @return string |
||
190 | */ |
||
191 | 94 | public function getHash() |
|
192 | { |
||
193 | 94 | if (!$this->hash) { |
|
194 | 94 | $this->hash = sha1($this->getName() . $this->getClass() . serialize($this->getConfig())); |
|
195 | 94 | } |
|
196 | 94 | return $this->hash; |
|
197 | } |
||
198 | } |
||
199 |
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.