Issues (162)

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/GenerateRestControllerCommand.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
namespace Tpg\ExtjsBundle\Command;
3
4
use Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand;
5
use Sensio\Bundle\GeneratorBundle\Command\Validators;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\HttpKernel\Bundle\Bundle;
10
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
11
use Tpg\ExtjsBundle\Generator\RestControllerGenerator;
12
13
class GenerateRestControllerCommand extends GeneratorCommand {
14
15
    /** @var  InputInterface */
16
    protected $input;
17
    /**
18
     * @var OutputInterface
19
     */
20
    protected $output;
21
22 2
    public function configure() {
23 2
        $this
24 2
            ->setDefinition(array(
25 2
                    new InputOption(
26 2
                        'controller',
27 2
                        '',
28 2
                        InputOption::VALUE_REQUIRED,
29
                        'The name of the controller to create'
30 2
                    ),
31 2
                    new InputOption(
32 2
                        'entity',
33 2
                        '',
34 2
                        InputOption::VALUE_REQUIRED,
35
                        "Entity this rest controller will manage"
36 2
                    ),
37 2
                    new InputOption(
38 2
                        'trait',
39 2
                        't',
40 2
                        InputOption::VALUE_NONE,
41
                        "Generate Trait and Rest Controller"
42 2
                    ),
43 2
                    new InputOption(
44 2
                        'mongo',
45 2
                        'm',
46 2
                        InputOption::VALUE_NONE,
47
                        "Generate Rest Controller for Mongo Document"
48 2
                    )
49 2
                ))
50 2
            ->setDescription('Generates a controller')
51 2
            ->setHelp(<<<EOT
52
The <info>generate:rest:controller</info> command helps you generates new FOSRest based controllers inside bundles.
53
54
If you want to specify the controller and entity to generate the controller for,
55
<info>php app/console generate:controller --controller=AcmeBlogBundle:Post --entity=AcmeBlogBundle:Post</info>
56
57
Every generated file is based on a template. There are default templates but they can be overriden by placing custom
58
templates in one of the following locations, by order of priority:
59
60
<info>BUNDLE_PATH/Resources/SensioGeneratorBundle/skeleton/controller
61
APP_PATH/Resources/SensioGeneratorBundle/skeleton/controller</info>
62
63
EOT
64 2
            )
65 2
            ->setName('generate:rest:controller');
66 2
    }
67
68 2
    public function execute(InputInterface $input, OutputInterface $output)
69
    {
70 2
        $this->input = $input;
71 2
        $this->output = $output;
72
73 2
        Validators::validateEntityName($input->getOption('entity'));
74
75
        // in SensioGeneratorBundle:v2.5.0 was BC break, changed method name. commit 59eebd0
76 2
        if (method_exists($this, 'getDialogHelper')) {
77
            $dialog = $this->getDialogHelper();
78
        } else {
79 2
            $dialog = $this->getQuestionHelper();
80
        }
81
82 2
        if ($input->getOption('trait')) {
83
            if (PHP_MAJOR_VERSION < 5 || PHP_MINOR_VERSION < 4) {
84
                throw new \RuntimeException('You need PHP > 5.4 to use trait feature');
85
            }
86
        }
87
88 2
        if (null === $input->getOption('controller')) {
89
            throw new \RuntimeException('The controller option must be provided.');
90
        }
91
92 2
        list($bundle, $controller) = $this->parseShortcutNotation($input->getOption('controller'));
93
        /** @var Bundle $bundle */
94 2 View Code Duplication
        if (is_string($bundle)) {
0 ignored issues
show
This code seems to be duplicated across 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...
95 2
            $bundle = Validators::validateBundleName($bundle);
96
97
            try {
98 2
                $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
99 2
            } catch (\Exception $e) {
100
                $output->writeln(sprintf('<bg=red>Bundle "%s" does not exists.</>', $bundle));
101
            }
102 2
        }
103
104 2
        $dialog->writeSection($output, 'Controller generation: ' . $controller . 'Controller (' . $bundle->getName() . ')');
105
106
        /** @var RestControllerGenerator $generator */
107 2
        $generator = $this->getGenerator($bundle);
108 2
        if ($input->getOption('trait')) {
109
            $output->writeln("<info>Generating Controller with Traits</info>");
110
            $generator->setUseTrait(true);
111
            $generator->generate($bundle,$controller,'','');
112
            $output->writeln("<info>Trait Controller Generated</info>");
113
            $generator->setUseTrait(false);
114
            $generator->setTemplateFile('UseTraitController.php');
115
            try {
116
                $generator->generate($bundle,$controller,'','');
117
                $output->writeln("<info>Controller Generated</info>");
118
            } catch (\RuntimeException $e) {
119
                $output->writeln("<info>Controller Skipped</info>");
120
            }
121
        } else {
122 2
            $generator->generate($bundle,$controller,'','');
123 2
            $output->writeln("<info>Controller Generated</info>");
124
        }
125
126 2
        $output->writeln('Generating the bundle code: <info>OK</info>');
127
128 2
        $dialog->writeGeneratorSummary($output, array());
129
130 2
    }
131
132 2
    protected function createGenerator()
133
    {
134 2
        $generator = new RestControllerGenerator($this->getContainer()->get('filesystem'));
135 2
        list($bundle, $entity) = $this->parseShortcutNotation($this->input->getOption('entity'));
136 2
        $generator->setEntityName($entity);
137 2 View Code Duplication
        if (is_string($bundle)) {
0 ignored issues
show
This code seems to be duplicated across 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...
138 2
            $bundle = Validators::validateBundleName($bundle);
139
            try {
140 2
                $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
141 2
            } catch (\Exception $e) {
142
                $this->output->writeln(sprintf('<bg=red>Bundle "%s" does not exists.</>', $bundle));
143
            }
144 2
        }
145
        /** @todo Check entity is a valid entity */
146 2
        if ($this->input->getOption("mongo")) {
147 1
            $generator->setMongo(true);
148 1
        }
149 2
        $generator->setEntityBundle($bundle);
150 2
        return $generator;
151
    }
152
153 2
    protected function getSkeletonDirs(BundleInterface $bundle = null)
154
    {
155 2
        $dirs = parent::getSkeletonDirs($bundle);
156 2
        $dirs[] = __DIR__.'/../Resources/skeleton';
157 2
        return $dirs;
158
    }
159
160
161 2
    public function parseShortcutNotation($shortcut)
162
    {
163 2
        $entity = str_replace('/', '\\', $shortcut);
164
165 2
        if (false === $pos = strpos($entity, ':')) {
166
            throw new \InvalidArgumentException(sprintf('The controller name must contain a : ("%s" given, expecting something like AcmeBlogBundle:Post)', $entity));
167
        }
168
169 2
        return array(substr($entity, 0, $pos), substr($entity, $pos + 1));
170
    }
171
}
172