Issues (17)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/MetaDataHelper.php (5 issues)

Upgrade to new PHP Analysis Engine

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

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

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

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

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