Issues (33)

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/Config.php (8 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
namespace T4webInfrastructure;
3
4
class Config
5
{
6
    /**
7
     * @var array
8
     */
9
    protected $entityMap = [];
10
11
    public function __construct(array $entityMap)
12
    {
13
        $this->entityMap = $entityMap;
14
    }
15
16
    /**
17
     * @param string $entityName
18
     *
19
     * @return string
20
     */
21 View Code Duplication
    public function getTable($entityName)
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...
22
    {
23
        if (!isset($this->entityMap[$entityName]['table'])) {
24
            throw new ConfigException(sprintf("entity_map not configured for %s", $entityName));
25
        }
26
27
        return $this->entityMap[$entityName]['table'];
28
    }
29
30
    /**
31
     * @param string $entityName
32
     * @return string
33
     */
34 View Code Duplication
    public function getEntityClass($entityName)
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...
35
    {
36
        if (!isset($this->entityMap[$entityName]['entityClass'])) {
37
            throw new ConfigException(sprintf("entity_map[entityClass] not configured for %s", $entityName));
38
        }
39
40
        return $this->entityMap[$entityName]['entityClass'];
41
    }
42
    
43
    /**
44
     * @param string $entityName
45
     * @return string
46
     */
47
    public function getCollectionClass($entityName)
48
    {
49
        if (!isset($this->entityMap[$entityName]['collectionClass'])) {
50
            return 'ArrayObject';
51
        }
52
53
        return $this->entityMap[$entityName]['collectionClass'];
54
    }
55
56
    /**
57
     * @param string $entityName
58
     * @param string $attribute
59
     * @return string
60
     */
61
    public function getFiled($entityName, $attribute)
62
    {
63 View Code Duplication
        if (!isset($this->entityMap[$entityName]['columnsAsAttributesMap'])) {
0 ignored issues
show
This code seems to be duplicated across 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...
64
            throw new ConfigException(sprintf("entity_map[columnsAsAttributesMap] not configured for %s", $entityName));
65
        }
66
67
        $field = array_search($attribute, $this->entityMap[$entityName]['columnsAsAttributesMap']);
68
69
        if (!$field) {
70
            throw new ConfigException(
71
                sprintf("attributes %s not exists in entity_map[columnsAsAttributesMap] config", $attribute)
72
            );
73
        }
74
75
        return $field;
76
    }
77
78
    /**
79
     * @param string $entityName
80
     * @param string $joinEntityName
81
     *
82
     * @return string
83
     */
84
    public function getRelationExpression($entityName, $joinEntityName)
85
    {
86 View Code Duplication
        if (!isset($this->entityMap[$entityName]['relations'][$joinEntityName])) {
0 ignored issues
show
This code seems to be duplicated across 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...
87
            throw new ConfigException(
88
                sprintf(
89
                    "entity_map for %s not configured with relation %s",
90
                    $entityName,
91
                    $joinEntityName
92
                )
93
            );
94
        }
95
96
        if (!isset($this->entityMap[$entityName]['relations'][$joinEntityName][0])
97
            || !isset($this->entityMap[$entityName]['relations'][$joinEntityName][1])) {
98
            throw new ConfigException(
99
                sprintf(
100
                    "entity_map for %s with relation %s must be array [field, joined-filed]",
101
                    $entityName,
102
                    $joinEntityName
103
                )
104
            );
105
        }
106
107
        return $this->entityMap[$entityName]['relations'][$joinEntityName][0].' = '
108
            . $this->entityMap[$entityName]['relations'][$joinEntityName][1];
109
    }
110
111
    /**
112
     * @param string $entityName
113
     * @param string $joinEntityName
114
     * @return bool
115
     */
116
    public function isRelationManyToMany($entityName, $joinEntityName)
117
    {
118 View Code Duplication
        if (!isset($this->entityMap[$entityName]['relations'][$joinEntityName])) {
0 ignored issues
show
This code seems to be duplicated across 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...
119
            throw new ConfigException(
120
                sprintf(
121
                    "entity_map for %s not configured with relation %s",
122
                    $entityName,
123
                    $joinEntityName
124
                )
125
            );
126
        }
127
128
        if (!isset($this->entityMap[$entityName]['relations'][$joinEntityName][0])
129
            || !isset($this->entityMap[$entityName]['relations'][$joinEntityName][1])
130
            || !isset($this->entityMap[$entityName]['relations'][$joinEntityName][2])) {
131
            return false;
132
        }
133
134
        return true;
135
    }
136
137
    /**
138
     * @param string $entityName
139
     * @param string $joinEntityName
140
     * @return array
141
     */
142
    public function getRelationManyToMany($entityName, $joinEntityName)
143
    {
144
        if (!$this->isRelationManyToMany($entityName, $joinEntityName)) {
145
            throw new ConfigException(
146
                sprintf(
147
                    "entity_map for %s with relation %s must be array [link-table, field, joined-filed]",
148
                    $entityName,
149
                    $joinEntityName
150
                )
151
            );
152
        }
153
154
        return [
155
            $this->entityMap[$entityName]['relations'][$joinEntityName][0],
156
            $this->entityMap[$entityName]['relations'][$joinEntityName][1],
157
            $this->entityMap[$entityName]['relations'][$joinEntityName][2],
158
        ];
159
    }
160
161
    /**
162
     * @param string $entityName
163
     *
164
     * @return array
165
     */
166
    public function getColumnsAsAttributesMap($entityName)
167
    {
168 View Code Duplication
        if (!isset($this->entityMap[$entityName]['columnsAsAttributesMap'])) {
0 ignored issues
show
This code seems to be duplicated across 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...
169
            throw new ConfigException(
170
                sprintf("entity_map[columnsAsAttributesMap] not configured for %s", $entityName)
171
            );
172
        }
173
174 View Code Duplication
        if (!is_array($this->entityMap[$entityName]['columnsAsAttributesMap'])) {
0 ignored issues
show
This code seems to be duplicated across 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...
175
            throw new ConfigException(
176
                sprintf("entity_map[columnsAsAttributesMap] for %s must be array", $entityName)
177
            );
178
        }
179
180
        return $this->entityMap[$entityName]['columnsAsAttributesMap'];
181
    }
182
183
    /**
184
     * @param string $entityName
185
     *
186
     * @return array
187
     */
188
    public function getSerializedColumns($entityName)
189
    {
190
        if (!isset($this->entityMap[$entityName]['serializedColumns'])) {
191
            return [];
192
        }
193
194 View Code Duplication
        if (!is_array($this->entityMap[$entityName]['serializedColumns'])) {
0 ignored issues
show
This code seems to be duplicated across 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...
195
            throw new ConfigException(
196
                sprintf("entity_map[serializedColumns] for %s must be array", $entityName)
197
            );
198
        }
199
200
        return $this->entityMap[$entityName]['serializedColumns'];
201
    }
202
203
    /**
204
     * @param string $entityName
205
     * @return string|null
206
     */
207
    public function getPrimaryKey($entityName)
208
    {
209
        if (isset($this->entityMap[$entityName]['primaryKey'])) {
210
            return $this->entityMap[$entityName]['primaryKey'];
211
        }
212
    }
213
214
    /**
215
     * @param string $entityName
216
     * @return string|null
217
     */
218
    public function getSequence($entityName)
219
    {
220
        if (isset($this->entityMap[$entityName]['sequence'])) {
221
            return $this->entityMap[$entityName]['sequence'];
222
        }
223
    }
224
225
    /**
226
     * @param string $entityName
227
     * @return string|null
228
     */
229
    public function getCriteriaMap($entityName)
230
    {
231
        if (isset($this->entityMap[$entityName]['criteriaMap'])) {
232
            return $this->entityMap[$entityName]['criteriaMap'];
233
        }
234
    }
235
236
    /**
237
     * @param string $entityName
238
     * @return string
239
     */
240
    public function getNamespace($entityName)
241
    {
242
        if (isset($this->entityMap[$entityName]['namespace'])) {
243
            return $this->entityMap[$entityName]['namespace'];
244
        }
245
246
        return "{$entityName}s\\$entityName";
247
    }
248
249
    public function getCustomCriteriaClass($entityName, $criteriaName)
250
    {
251
        if (class_exists($criteriaName)) {
252
            return $criteriaName;
253
        }
254
255
        $entityNamespace = $this->getNamespace($entityName);
256
        $className = "$entityNamespace\\Infrastructure\\Criteria\\$criteriaName";
257
        
258
        return $className;
259
    }
260
}
261