Issues (3099)

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.

GeneratorBundle/Command/GenerateEntityCommand.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 Kunstmaan\GeneratorBundle\Command;
4
5
use Kunstmaan\GeneratorBundle\Generator\DefaultEntityGenerator;
6
use Symfony\Component\Console\Input\InputOption;
7
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
8
9
/**
10
 * GenerateEntityCommand
11
 */
12
class GenerateEntityCommand extends KunstmaanGenerateCommand
13
{
14
    /**
15
     * @var BundleInterface
16
     */
17
    private $bundle;
18
19
    /**
20
     * @var string
21
     */
22
    private $prefix;
23
24
    /**
25
     * @var string
26
     */
27
    private $entityName;
28
29
    /**
30
     * @var array
31
     */
32
    private $fields;
33
34
    /**
35
     * @var bool
36
     */
37
    private $withRepository;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function configure()
43
    {
44
        $this
45
            ->setName('kuma:generate:entity')
46
            ->setDescription('Generates a new Doctrine entity inside a bundle')
47
            ->addOption('prefix', '', InputOption::VALUE_OPTIONAL, 'The prefix to be used in the table names of the generated entities')
48
            ->addOption('with-repository', null, InputOption::VALUE_NONE, 'Whether to generate the entity repository or not (y/n)')
49
            ->setHelp(<<<'EOT'
50
The <info>kuma:generate:entity</info> task generates a new entity inside a bundle:
51
52
<info>php bin/console kuma:generate:entity</info>
53
54
The command can also generate the corresponding entity repository class with the
55
<comment>--with-repository</comment> option:
56
57
<info>php bin/console kuma:generate:entity --with-repository</info>
58
59
Use the <info>--prefix</info> option to add a prefix to the table names of the generated entities
60
61
<info>php bin/console kuma:generate:entity --prefix=demo_</info>
62
EOT
63
            );
64
    }
65
66
    /**
67
     * @return DefaultEntityGenerator
68
     */
69 View Code Duplication
    protected function createGenerator()
70
    {
71
        $filesystem = $this->getContainer()->get('filesystem');
72
        $registry = $this->getContainer()->get('doctrine');
73
74
        return new DefaultEntityGenerator($filesystem, $registry, '/entity', $this->assistant, $this->getContainer());
75
    }
76
77
    /**
78
     * The text to be displayed on top of the generator.
79
     *
80
     * @return string|array
81
     */
82
    protected function getWelcomeText()
83
    {
84
        return 'Welcome to the Kunstmaan entity generator';
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    protected function doExecute()
91
    {
92
        $this->assistant->writeSection('Entity generation');
93
94
        $this->createGenerator()->generate($this->bundle, $this->entityName, $this->prefix, $this->fields, $this->withRepository);
95
96
        $this->assistant->writeSection('Entity successfully created', 'bg=green;fg=black');
97
        $this->assistant->writeLine(array(
98
            'Make sure you update your database first before you test the entity:',
99
            '    Directly update your database:          <comment>bin/console doctrine:schema:update --force</comment>',
100
            '    Create a Doctrine migration and run it: <comment>bin/console doctrine:migrations:diff && app/console doctrine:migrations:migrate</comment>',
101
        ));
102
103
        return 0;
104
    }
105
106
    /**
107
     * Do the interaction with the end user.
108
     */
109
    protected function doInteract()
110
    {
111
        $this->assistant->writeLine(array("This command helps you to generate a new entity.\n"));
112
113
        /*
114
         * Ask for which bundle we need to create the pagepart
115
         */
116
        $this->bundle = $this->askForBundleName('entity');
117
118
        /*
119
         * Ask the database table prefix
120
         */
121
        $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
122
123
        /*
124
         * Ask the name of the pagepart
125
         */
126
        $this->assistant->writeLine(array(
127
            '',
128
            'The name of your Entity: For example: <comment>Address</comment>',
129
            '',
130
        ));
131
        $generator = $this->getGenerator();
132
        $bundlePath = $this->bundle->getPath();
133
        $name = $this->assistant->askAndValidate(
134
            'Entity name',
135
            function ($name) use ($generator, $bundlePath) {
136
                // Check reserved words
137
                if ($generator->isReservedKeyword($name)) {
138
                    throw new \InvalidArgumentException(sprintf('"%s" is a reserved word', $name));
139
                }
140
141
                if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $name)) {
142
                    throw new \InvalidArgumentException(sprintf('Invalid entity name: %s', $name));
143
                }
144
145
                // Check that entity does not already exist
146
                if (file_exists($bundlePath.'/Entity/'.$name.'.php')) {
147
                    throw new \InvalidArgumentException(sprintf('Entity "%s" already exists', $name));
148
                }
149
150
                return $name;
151
            }
152
        );
153
        $this->entityName = $name;
154
155
        /*
156
         * Ask which fields need to be present
157
         */
158
        $this->assistant->writeLine(array("\nInstead of starting with a blank entity, you can add some fields now.\n"));
159
        $fields = $this->askEntityFields($this->bundle);
160
        $this->fields = array_map(function ($fieldInfo) {
161
            switch ($fieldInfo['type']) {
162
                case 'image':
163
                    return $this->getEntityFields($this->bundle, $this->entityName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'],
164
                        $fieldInfo['extra'], true, $fieldInfo['minHeight'], $fieldInfo['maxHeight'], $fieldInfo['minWidth'], $fieldInfo['maxWidth'], $fieldInfo['mimeTypes']);
165
166
                    break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
167
168
                case 'media':
169
                    return $this->getEntityFields($this->bundle, $this->entityName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'],
170
                        $fieldInfo['extra'], true, null, null, null, null, $fieldInfo['mimeTypes']);
171
172
                    break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
173
174
                default:
175
                    return $this->getEntityFields($this->bundle, $this->entityName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true);
176
177
                    break;
0 ignored issues
show
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
178
            }
179
        }, $fields);
180
181
        /*
182
         * Ask if a repository class needs to be generated
183
         */
184
        $this->withRepository = $this->askForWithRepository();
185
    }
186
187
    /**
188
     * @return bool
189
     */
190 View Code Duplication
    protected function askForWithRepository()
191
    {
192
        $withRepositoryOption = $this->assistant->getOption('with-repository');
193
        if ($withRepositoryOption != 'y' && $withRepositoryOption != 'n') {
194
            /** @var $question */
195
            $withRepositoryOption = $this->assistant->askConfirmation("\nDo you want to generate a repository class for the entity ? (y/n)\n", '', '?', false);
196
        }
197
198
        return $withRepositoryOption == 'y';
199
    }
200
}
201