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.

Twig/SchemaDumperExtension.php (3 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\Twig;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use Doctrine\DBAL\Schema\Column;
8
use Doctrine\DBAL\Types\Type;
9
10
class SchemaDumperExtension extends \Twig_Extension
11
{
12
    /**
13
     * @var ManagerRegistry
14
     */
15
    protected $managerRegistry;
16
17
    /**
18
     * @var AbstractPlatform
19
     */
20
    protected $platform;
21
22
    /**
23
     * @var Column
24
     */
25
    protected $defaultColumn;
26
27
    /**
28
     * @var array
29
     */
30
    protected $defaultColumnOptions = [];
31
32
    /**
33
     * @var array
34
     */
35
    protected $optionNames = [
36
        'default',
37
        'notnull',
38
        'length',
39
        'precision',
40
        'scale',
41
        'fixed',
42
        'unsigned',
43
        'autoincrement'
44
    ];
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getName()
50
    {
51
        return 'schema_dumper_extension';
52
    }
53
54
    /**
55
     * @param ManagerRegistry $managerRegistry
56
     */
57
    public function __construct(ManagerRegistry $managerRegistry)
58
    {
59
        $this->managerRegistry = $managerRegistry;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getFunctions()
66
    {
67
        return array(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('rdv_migrat..., 'getColumnOptions')); (array<string,Twig_Function_Method>) is incompatible with the return type declared by the interface Twig_ExtensionInterface::getFunctions of type Twig_SimpleFunction[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
68
            'rdv_migration_get_schema_column_options' => new \Twig_Function_Method($this, 'getColumnOptions'),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Function_Method has been deprecated with message: since 1.12 (to be removed in 2.0)

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
69
        );
70
    }
71
72
    /**
73
     * @param Column $column
74
     * @return array
75
     */
76
    public function getColumnOptions(Column $column)
77
    {
78
        $defaultOptions = $this->getDefaultOptions();
79
        $platform = $this->getPlatform();
80
        $options = [];
81
82
        foreach ($this->optionNames as $optionName) {
83
            $value = $this->getColumnOption($column, $optionName);
84
            if ($value !== $defaultOptions[$optionName]) {
85
                $options[$optionName] = $value;
86
            }
87
        }
88
89
        $comment = $column->getComment();
90
        if ($platform && $platform->isCommentedDoctrineType($column->getType())) {
91
            $comment .= $platform->getDoctrineTypeComment($column->getType());
92
        }
93
        if (!empty($comment)) {
94
            $options['comment'] = $comment;
95
        }
96
97
        return $options;
98
    }
99
100
    /**
101
     * @param Column $column
102
     * @param string $optionName
103
     * @return mixed
104
     */
105
    protected function getColumnOption(Column $column, $optionName)
106
    {
107
        $method = "get" . $optionName;
108
109
        return $column->$method();
110
    }
111
112
    /**
113
     * @return AbstractPlatform
114
     */
115
    protected function getPlatform()
116
    {
117
        if (!$this->platform) {
118
            $this->platform = $this->managerRegistry->getConnection()->getDatabasePlatform();
119
        }
120
121
        return $this->platform;
122
    }
123
124
    /**
125
     * @return array
126
     */
127
    protected function getDefaultOptions()
128
    {
129
        if (!$this->defaultColumn) {
130
            $this->defaultColumn = new Column('_template_', Type::getType(Type::STRING));
131
        }
132
        if (!$this->defaultColumnOptions) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->defaultColumnOptions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
133
            foreach ($this->optionNames as $optionName) {
134
                $this->defaultColumnOptions[$optionName] = $this->getColumnOption($this->defaultColumn, $optionName);
135
            }
136
        }
137
138
        return $this->defaultColumnOptions;
139
    }
140
}
141