Issues (7)

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.

NamingStrategy/UnderscoredClassNamespacePrefix.php (1 issue)

Labels
Severity

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
declare(strict_types=1);
4
5
namespace RunOpenCode\Bundle\DoctrineNamingStrategy\NamingStrategy;
6
7
use Doctrine\ORM\Mapping\NamingStrategy;
8
use RunOpenCode\Bundle\DoctrineNamingStrategy\Exception\RuntimeException;
9
10
/**
11
 * @psalm-suppress UnusedClass
12
 */
13
final class UnderscoredClassNamespacePrefix implements NamingStrategy
14
{
15
    private int $case;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
16
17
    protected bool $joinTableFieldSuffix;
18
19
    /**
20
     * @var string[]
21
     */
22
    protected array $whitelist;
23
24
    /**
25
     * @var string[]
26
     */
27
    protected array $blacklist;
28
29
    /**
30
     * @var array<string, string>
31
     */
32
    protected array $map;
33
34
    /**
35
     * @psalm-param array{case?: int, map?: array<string, string>, blacklist?: string[], whitelist?: string[], join_table_field_suffix?: bool } $configuration
36
     *
37
     * @throws RuntimeException
38
     */
39 25
    public function __construct(array $configuration = [])
40
    {
41
        /**
42
         * @psalm-var array{case: int, map: array<string, string>, blacklist: string[], whitelist: string[], join_table_field_suffix: bool } $configuration
43
         */
44 25
        $configuration = array_merge([
45 25
            'case'                    => CASE_LOWER,
46
            'map'                     => [],
47
            'whitelist'               => [],
48
            'blacklist'               => [],
49
            'join_table_field_suffix' => true,
50
        ], $configuration);
51
52 25
        if (\count($configuration['whitelist']) > 0 && \count($configuration['blacklist']) > 0) {
53 1
            throw new RuntimeException('You can use whitelist or blacklist or none of mentioned lists, but not booth.');
54
        }
55
56 24
        $this->case = $configuration['case'];
57
        /**
58
         * @psalm-suppress MixedPropertyTypeCoercion
59
         */
60
        $this->map       = \array_map(\Closure::bind(function (string $prefix) {
61 17
            return $this->underscore($prefix);
62 24
        }, $this), $configuration['map']);
63
        $this->blacklist = \array_map(static function (string $class) {
64 1
            return \ltrim($class, '\\');
65 24
        }, $configuration['blacklist']);
66
        $this->whitelist = \array_map(static function (string $class) {
67 1
            return \ltrim($class, '\\');
68 24
        }, $configuration['whitelist']);
69
70 24
        $this->joinTableFieldSuffix = $configuration['join_table_field_suffix'];
71 24
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 14
    public function classToTableName($className): string
77
    {
78 14
        $prefix   = $this->getTableNamePrefix($className);
79 14
        $position = \strrpos($className, '\\');
80
81 14
        if (false !== $position) {
82 14
            $className = \substr($className, ($position + 1));
83
        }
84
85 14
        return $prefix . $this->underscore($className);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 7
    public function propertyToColumnName($propertyName, $className = null): string
92
    {
93 7
        return $this->underscore($propertyName);
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 3
    public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null): string
100
    {
101 3
        return $this->underscore($propertyName) . '_' . $this->underscore($embeddedColumnName);
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 6
    public function referenceColumnName(): string
108
    {
109 6
        return $this->case === CASE_UPPER ? 'ID' : 'id';
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 2
    public function joinColumnName($propertyName): string
116
    {
117 2
        return $this->underscore($propertyName) . '_' . $this->referenceColumnName();
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 3
    public function joinTableName($sourceEntity, $targetEntity, $propertyName = null): string
124
    {
125 3
        $tableName = $this->classToTableName($sourceEntity) . '_' . $this->classToTableName($targetEntity);
126 3
        $suffix    = $this->joinTableFieldSuffix && null !== $propertyName ? '_' . $this->propertyToColumnName($propertyName, $sourceEntity) : '';
127
128 3
        return $tableName . $suffix;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134 2
    public function joinKeyColumnName($entityName, $referencedColumnName = null): string
135
    {
136 2
        return $this->classToTableName($entityName) . '_' .
137 2
            ($referencedColumnName ? $this->underscore($referencedColumnName) : $this->referenceColumnName());
138
    }
139
140 14
    private function getTableNamePrefix(string $className): string
141
    {
142 14
        $className = \ltrim($className, '\\');
143
144 14
        foreach ($this->blacklist as $blacklist) {
145 1
            if (0 === \strpos($className, $blacklist)) {
146 1
                return '';
147
            }
148
        }
149
150 13
        foreach ($this->map as $namespace => $prefix) {
151 13
            if (0 === \strpos($className, $namespace)) {
152 13
                foreach ($this->whitelist as $whitelistedNamespace) {
153 1
                    if (0 === \strpos($className, $whitelistedNamespace)) {
154 1
                        return $prefix . '_';
155
                    }
156
                }
157
158 12
                return 0 === \count($this->whitelist) ? ($prefix . '_') : '';
159
            }
160
        }
161
162 6
        return '';
163
    }
164
165 23
    private function underscore(string $literal): string
166
    {
167
        /** @var string $literal */
168 23
        $literal = \preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $literal);
169
170 23
        if (CASE_UPPER === $this->case) {
171 14
            return \strtoupper($literal);
172
        }
173
174 17
        return \strtolower($literal);
175
    }
176
}
177