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.

Command/GeneratePagePartCommand.php (2 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\PagePartGenerator;
6
use Symfony\Component\Console\Input\InputOption;
7
8
/**
9
 * Generates a new pagepart
10
 */
11
class GeneratePagePartCommand extends KunstmaanGenerateCommand
12
{
13
    /**
14
     * @var BundleInterface
15
     */
16
    private $bundle;
17
18
    /**
19
     * @var string
20
     */
21
    private $prefix;
22
23
    /**
24
     * @var string
25
     */
26
    private $pagepartName;
27
28
    /**
29
     * @var array
30
     */
31
    private $fields;
32
33
    /**
34
     * @var array
35
     */
36
    private $sections = array();
37
38
    /**
39
     * @var bool
40
     */
41
    private $behatTest;
42
43
    /**
44
     * @see Command
45
     */
46
    protected function configure()
47
    {
48
        $this->setDescription('Generates a new pagepart')
49
            ->setHelp(<<<'EOT'
50
The <info>kuma:generate:pagepart</info> command generates a new pagepart and the pagepart configuration.
51
52
<info>php bin/console kuma:generate:pagepart</info>
53
EOT
54
            )
55
            ->addOption('prefix', '', InputOption::VALUE_OPTIONAL, 'The prefix to be used in the table name of the generated entity')
56
            ->setName('kuma:generate:pagepart');
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    protected function getWelcomeText()
63
    {
64
        return 'Welcome to the Kunstmaan pagepart generator';
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    protected function doExecute()
71
    {
72
        $this->assistant->writeSection('PagePart generation');
73
74
        $this->createGenerator()->generate($this->bundle, $this->pagepartName, $this->prefix, $this->fields, $this->sections, $this->behatTest);
75
76
        $this->assistant->writeSection('PagePart successfully created', 'bg=green;fg=black');
77
        $this->assistant->writeLine(array(
78
            'Make sure you update your database first before you test the pagepart:',
79
            '    Directly update your database:          <comment>bin/console doctrine:schema:update --force</comment>',
80
            '    Create a Doctrine migration and run it: <comment>bin/console doctrine:migrations:diff && bin/console doctrine:migrations:migrate</comment>',
81
            ($this->behatTest ? 'A new behat test is created, to run it: <comment>bin/behat --tags \'@'.$this->pagepartName.'\' @'.$this->bundle->getName().'</comment>' : ''),
82
        ));
83
84
        return 0;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    protected function doInteract()
91
    {
92
        if (!$this->isBundleAvailable('KunstmaanPagePartBundle')) {
93
            $this->assistant->writeError('KunstmaanPagePartBundle not found', true);
94
        }
95
96
        $this->assistant->writeLine(array("This command helps you to generate a new pagepart.\n"));
97
98
        /*
99
         * Ask for which bundle we need to create the pagepart
100
         */
101
        $this->bundle = $this->askForBundleName('pagepart');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->askForBundleName('pagepart') of type object<Symfony\Component...Bundle\BundleInterface> is incompatible with the declared type object<Kunstmaan\Generat...ommand\BundleInterface> of property $bundle.

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...
102
103
        /*
104
         * Ask the database table prefix
105
         */
106
        $this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
107
108
        /*
109
         * Ask the name of the pagepart
110
         */
111
        $this->assistant->writeLine(array(
112
            '',
113
            'The name of your PagePart: For example: <comment>ContentBoxPagePart</comment>',
114
            '',
115
        ));
116
        $generator = $this->getGenerator();
117
        $bundlePath = $this->bundle->getPath();
118
        $name = $this->assistant->askAndValidate(
119
            'PagePart name',
120 View Code Duplication
            function ($name) use ($generator, $bundlePath) {
121
                // Check reserved words
122
                if ($generator->isReservedKeyword($name)) {
123
                    throw new \InvalidArgumentException(sprintf('"%s" is a reserved word', $name));
124
                }
125
126
                // Name should end on PagePart
127
                if (!preg_match('/PagePart$/', $name)) {
128
                    throw new \InvalidArgumentException('The pagepart name must end with PagePart');
129
                }
130
131
                // Name should contain more characters than PagePart
132
                if (strlen($name) <= strlen('PagePart') || !preg_match('/^[a-zA-Z]+$/', $name)) {
133
                    throw new \InvalidArgumentException('Invalid pagepart name');
134
                }
135
136
                // Check that entity does not already exist
137
                if (file_exists($bundlePath.'/Entity/PageParts/'.$name.'.php')) {
138
                    throw new \InvalidArgumentException(sprintf('PagePart or entity "%s" already exists', $name));
139
                }
140
141
                return $name;
142
            }
143
        );
144
        $this->pagepartName = $name;
145
146
        /*
147
         * Ask which fields need to be present
148
         */
149
        $this->assistant->writeLine(array("\nInstead of starting with a blank pagepart, you can add some fields now.\n"));
150
        $fields = $this->askEntityFields($this->bundle);
151
        $this->fields = array();
152
        foreach ($fields as $fieldInfo) {
153
            if ($fieldInfo['type'] == 'image') {
154
                $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'],
155
                    $fieldInfo['extra'], true, $fieldInfo['minHeight'], $fieldInfo['maxHeight'], $fieldInfo['minWidth'], $fieldInfo['maxWidth'], $fieldInfo['mimeTypes']);
156
            } elseif ($fieldInfo['type'] == 'media') {
157
                $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'],
158
                    $fieldInfo['extra'], true, null, null, null, null, $fieldInfo['mimeTypes']);
159
            } else {
160
                $this->fields[] = $this->getEntityFields($this->bundle, $this->pagepartName, $this->prefix, $fieldInfo['name'], $fieldInfo['type'], $fieldInfo['extra'], true);
161
            }
162
        }
163
164
        /**
165
         * Ask for which page sections we should enable this pagepart
166
         */
167
        $question = 'In which page section configuration file(s) do you want to add the pagepart (multiple possible, separated by comma)';
168
        $this->sections = $this->askForSections($question, $this->bundle, true);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->askForSections($q...n, $this->bundle, true) can be null. However, the property $sections is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

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

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
169
170
        /*
171
         * Ask that you want to create behat tests for the new pagepart, if possible
172
         */
173
        if (count($this->sections) > 0 && $this->canGenerateBehatTests($this->bundle)) {
174
            $this->behatTest = $this->assistant->askConfirmation('Do you want to generate behat tests for this pagepart? (y/n)', 'y');
175
        } else {
176
            $this->behatTest = false;
177
        }
178
    }
179
180
    /**
181
     * Get the generator.
182
     *
183
     * @return PagePartGenerator
184
     */
185 View Code Duplication
    protected function createGenerator()
186
    {
187
        $filesystem = $this->getContainer()->get('filesystem');
188
        $registry = $this->getContainer()->get('doctrine');
189
190
        return new PagePartGenerator($filesystem, $registry, '/pagepart', $this->assistant, $this->getContainer());
191
    }
192
}
193