Issues (75)

Security Analysis    not enabled

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.

Migration/Extension/RenameExtension.php (13 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
namespace RDV\Bundle\MigrationBundle\Migration\Extension;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
7
use Doctrine\DBAL\Schema\Index;
8
use Doctrine\DBAL\Schema\Schema;
9
use Doctrine\DBAL\Schema\Table;
10
use Doctrine\DBAL\Schema\TableDiff;
11
use RDV\Bundle\MigrationBundle\Migration\QueryBag;
12
use RDV\Bundle\MigrationBundle\Migration\Schema\Column;
13
use RDV\Bundle\MigrationBundle\Migration\SqlMigrationQuery;
14
use RDV\Bundle\MigrationBundle\Tools\DbIdentifierNameGenerator;
15
16
class RenameExtension implements DatabasePlatformAwareInterface, NameGeneratorAwareInterface
17
{
18
    /**
19
     * @var AbstractPlatform
20
     */
21
    protected $platform;
22
23
    /**
24
     * @var DbIdentifierNameGenerator
25
     */
26
    protected $nameGenerator;
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function setDatabasePlatform(AbstractPlatform $platform)
32
    {
33
        $this->platform = $platform;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function setNameGenerator(DbIdentifierNameGenerator $nameGenerator)
40
    {
41
        $this->nameGenerator = $nameGenerator;
42
    }
43
44
    /**
45
     * Renames a table
46
     *
47
     * @param Schema   $schema
48
     * @param QueryBag $queries
49
     * @param string   $oldTableName
50
     * @param string   $newTableName
51
     */
52
    public function renameTable(Schema $schema, QueryBag $queries, $oldTableName, $newTableName)
53
    {
54
        $table         = $schema->getTable($oldTableName);
55
        $diff          = new TableDiff($table->getName());
56
        $diff->newName = $newTableName;
57
58
        $renameQuery = new SqlMigrationQuery(
59
            $this->platform->getAlterTableSQL($diff)
60
        );
61
62
        $queries->addQuery($renameQuery);
63
    }
64
65
    /**
66
     * Renames a column
67
     *
68
     * @param Schema   $schema
69
     * @param QueryBag $queries
70
     * @param Table    $table
71
     * @param string   $oldColumnName
72
     * @param string   $newColumnName
73
     */
74
    public function renameColumn(Schema $schema, QueryBag $queries, Table $table, $oldColumnName, $newColumnName)
0 ignored issues
show
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        $column = new Column(['column' => $table->getColumn($oldColumnName)]);
77
        $column->changeName($newColumnName);
78
        $diff                 = new TableDiff($table->getName());
79
        $diff->renamedColumns = [$oldColumnName => $column];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($oldColumnName => $column) of type array<string,object<RDV\...gration\Schema\Column>> is incompatible with the declared type array<integer,object<Doc...ne\DBAL\Schema\Column>> of property $renamedColumns.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
80
81
        $renameQuery = new SqlMigrationQuery(
82
            $this->platform->getAlterTableSQL($diff)
83
        );
84
85
        $queries->addQuery($renameQuery);
86
    }
87
88
    /**
89
     * Create an index without check of table and columns existence.
90
     * This method can be helpful when you need to create an index for renamed table or column
91
     *
92
     * @param Schema      $schema
93
     * @param QueryBag    $queries
94
     * @param string      $tableName
95
     * @param string[]    $columnNames
96
     * @param string|null $indexName
97
     */
98 View Code Duplication
    public function addIndex(
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...
99
        Schema $schema,
0 ignored issues
show
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
        QueryBag $queries,
101
        $tableName,
102
        array $columnNames,
103
        $indexName = null
104
    ) {
105
        if (!$indexName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $indexName of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
106
            $indexName = $this->nameGenerator->generateIndexName($tableName, $columnNames);
107
        }
108
        $index              = new Index($indexName, $columnNames);
109
        $diff               = new TableDiff($tableName);
110
        $diff->addedIndexes = [$indexName => $index];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($indexName => $index) of type array<string,object<Doctrine\DBAL\Schema\Index>> is incompatible with the declared type array<integer,object<Doctrine\DBAL\Schema\Index>> of property $addedIndexes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
111
112
        $renameQuery = new SqlMigrationQuery(
113
            $this->platform->getAlterTableSQL($diff)
114
        );
115
116
        $queries->addQuery($renameQuery);
117
    }
118
119
    /**
120
     * Create an unique index without check of table and columns existence.
121
     * This method can be helpful when you need to create an index for renamed table or column
122
     *
123
     * @param Schema      $schema
124
     * @param QueryBag    $queries
125
     * @param string      $tableName
126
     * @param string[]    $columnNames
127
     * @param string|null $indexName
128
     */
129 View Code Duplication
    public function addUniqueIndex(
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...
130
        Schema $schema,
0 ignored issues
show
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131
        QueryBag $queries,
132
        $tableName,
133
        array $columnNames,
134
        $indexName = null
135
    ) {
136
        if (!$indexName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $indexName of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
137
            $indexName = $this->nameGenerator->generateIndexName($tableName, $columnNames, true);
138
        }
139
        $index              = new Index($indexName, $columnNames, true);
140
        $diff               = new TableDiff($tableName);
141
        $diff->addedIndexes = [$indexName => $index];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($indexName => $index) of type array<string,object<Doctrine\DBAL\Schema\Index>> is incompatible with the declared type array<integer,object<Doctrine\DBAL\Schema\Index>> of property $addedIndexes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
142
143
        $renameQuery = new SqlMigrationQuery(
144
            $this->platform->getAlterTableSQL($diff)
145
        );
146
147
        $queries->addQuery($renameQuery);
148
    }
149
150
    /**
151
     * Create a foreign key constraint without check of table and columns existence.
152
     * This method can be helpful when you need to create a constraint for renamed table or column
153
     *
154
     * @param Schema      $schema
155
     * @param QueryBag    $queries
156
     * @param string      $tableName
157
     * @param string      $foreignTable
158
     * @param string[]    $localColumnNames
159
     * @param string[]    $foreignColumnNames
160
     * @param array       $options
161
     * @param string|null $constraintName
162
     */
163
    public function addForeignKeyConstraint(
164
        Schema $schema,
0 ignored issues
show
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
        QueryBag $queries,
166
        $tableName,
167
        $foreignTable,
168
        array $localColumnNames,
169
        array $foreignColumnNames,
170
        array $options = [],
171
        $constraintName = null
172
    ) {
173
        if (!$constraintName) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $constraintName of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
174
            $constraintName = $this->nameGenerator->generateForeignKeyConstraintName(
175
                $tableName,
176
                $localColumnNames
177
            );
178
        }
179
        $constraint = new ForeignKeyConstraint(
180
            $localColumnNames,
181
            $foreignTable,
182
            $foreignColumnNames,
183
            $constraintName,
184
            $options
185
        );
186
        $diff = new TableDiff($tableName);
187
        $diff->addedForeignKeys = [$constraintName => $constraint];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($constraintName => $constraint) of type array<string,object<Doct...\ForeignKeyConstraint>> is incompatible with the declared type array<integer,object<Doc...\ForeignKeyConstraint>> of property $addedForeignKeys.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
188
189
        $renameQuery = new SqlMigrationQuery(
190
            $this->platform->getAlterTableSQL($diff)
191
        );
192
193
        $queries->addQuery($renameQuery);
194
    }
195
}
196