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