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 | /* |
||
4 | * @copyright (c) 2019 Mendel <[email protected]> |
||
5 | * @license see license.txt |
||
6 | */ |
||
7 | |||
8 | namespace drycart\data; |
||
9 | |||
10 | /** |
||
11 | * Metadata for some class |
||
12 | * i.e. some data from comments for class, fields, methods |
||
13 | * |
||
14 | * @author mendel |
||
15 | */ |
||
16 | class MetaDataHelper |
||
17 | { |
||
18 | /** |
||
19 | * Session cache |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $cache = []; |
||
23 | |||
24 | /** |
||
25 | * Get current cache data for store to external cache |
||
26 | * @return array |
||
27 | */ |
||
28 | public function getCache() : array |
||
29 | { |
||
30 | return $this->cache; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Set cache data from external cache |
||
35 | * @param array $cache |
||
36 | * @return void |
||
37 | */ |
||
38 | public function setCache(array $cache) : void |
||
39 | { |
||
40 | $this->cache = $cache; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Metadata for class |
||
45 | * |
||
46 | * @param string $className |
||
47 | * @return array |
||
48 | */ |
||
49 | public function classMeta(string $className) : array |
||
50 | { |
||
51 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
52 | $classReflector = new \ReflectionClass($className); |
||
53 | $doc = $classReflector->getDocComment(); |
||
54 | $this->cache[$className][__FUNCTION__] = StrHelper::parseDocComment($doc); |
||
55 | } |
||
56 | return $this->cache[$className][__FUNCTION__]; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get rules for class |
||
61 | * |
||
62 | * @param string $className |
||
63 | * @return array |
||
64 | */ |
||
65 | View Code Duplication | public function classRules(string $className) : array |
|
0 ignored issues
–
show
|
|||
66 | { |
||
67 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
68 | $this->cache[$className][__FUNCTION__] = $this->prepareRules($this->classMeta($className)); |
||
69 | } |
||
70 | return $this->cache[$className][__FUNCTION__]; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Metadata for methods |
||
75 | * meta at name for future add return type info |
||
76 | * |
||
77 | * @param string $className |
||
78 | * @return array[] |
||
79 | */ |
||
80 | View Code Duplication | public function methodsMeta(string $className) : array |
|
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. ![]() |
|||
81 | { |
||
82 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
83 | $this->cache[$className][__FUNCTION__] = []; |
||
84 | $classReflector = new \ReflectionClass($className); |
||
85 | foreach($classReflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $line) { |
||
86 | if(!$line->isStatic()) { |
||
87 | $doc = $line->getDocComment(); |
||
88 | $this->cache[$className][__FUNCTION__][$line->name] = StrHelper::parseDocComment($doc); |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 | return $this->cache[$className][__FUNCTION__]; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Get methods rules |
||
97 | * |
||
98 | * @param string $className |
||
99 | * @return array |
||
100 | */ |
||
101 | View Code Duplication | public function methodsRules(string $className) : array |
|
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. ![]() |
|||
102 | { |
||
103 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
104 | $this->cache[$className][__FUNCTION__] = $this->prepareRulesArray($this->methodsMeta($className)); |
||
105 | } |
||
106 | return $this->cache[$className][__FUNCTION__]; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Metadata for fields |
||
111 | * meta at name for future add return type info |
||
112 | * |
||
113 | * @param string $className |
||
114 | * @return array |
||
115 | */ |
||
116 | View Code Duplication | public function fieldsMeta(string $className) : array |
|
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. ![]() |
|||
117 | { |
||
118 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
119 | $this->cache[$className][__FUNCTION__] = []; |
||
120 | $classReflector = new \ReflectionClass($className); |
||
121 | foreach($classReflector->getProperties(\ReflectionProperty::IS_PUBLIC) as $line) { |
||
122 | if(!$line->isStatic()) { |
||
123 | $doc = $line->getDocComment(); |
||
124 | $this->cache[$className][__FUNCTION__][$line->name] = StrHelper::parseDocComment($doc); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | return $this->cache[$className][__FUNCTION__]; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Get fields rules |
||
133 | * |
||
134 | * @param string $className |
||
135 | * @return array |
||
136 | */ |
||
137 | View Code Duplication | public function fieldsRules(string $className) : array |
|
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. ![]() |
|||
138 | { |
||
139 | if(!isset($this->cache[$className][__FUNCTION__])) { |
||
140 | $this->cache[$className][__FUNCTION__] = $this->prepareRulesArray($this->fieldsMeta($className)); |
||
141 | } |
||
142 | return $this->cache[$className][__FUNCTION__]; |
||
143 | } |
||
144 | |||
145 | protected function prepareRulesArray(array $data) : array |
||
146 | { |
||
147 | $result = []; |
||
148 | foreach($data as $name=>$lines) { |
||
149 | $result[$name] = $this->prepareRules($lines); |
||
150 | } |
||
151 | return $result; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Prepare rules i.e. array of "meta" parameters group by first word |
||
156 | * |
||
157 | * @param array $lines |
||
158 | * @return array |
||
159 | */ |
||
160 | protected function prepareRules(array $lines) : array |
||
161 | { |
||
162 | $result = []; |
||
163 | foreach($lines as $line) { |
||
164 | $data = explode(' ', $line); |
||
165 | $key = array_shift($data); // take first |
||
166 | $result[$key][] = $data; |
||
167 | } |
||
168 | return $result; |
||
169 | } |
||
170 | } |
||
171 |
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.