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/GenerateEntityCommand.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 Tpg\ExtjsBundle\Command;
4
5
use Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataCollection;
6
use Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory;
7
use Doctrine\ORM\Mapping\ClassMetadata;
8
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Generates Extjs model based on entity
16
 */
17
class GenerateEntityCommand extends ContainerAwareCommand
18
{
19
    /**
20
     * @inheritdoc
21
     */
22 2
    public function configure()
23
    {
24 2
        parent::configure();
25
26 2
        $this->setName('generate:extjs:entity');
27 2
        $this->addArgument('name', InputArgument::REQUIRED, "A bundle name, a namespace, or a class name");
28 2
        $this->addOption(
29 2
            'output',
30 2
            '',
31 2
            InputOption::VALUE_OPTIONAL,
32
            "File/Directory for the output of the ExtJs model file"
33 2
        );
34 2
        $this->addOption('overwrite', 'y', InputOption::VALUE_NONE, "Overwrite existing file");
35 2
        $this->setDescription("Generate Sencha ExtJs model base on an existing PHP entity");
36 2
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $reader = $this->getContainer()->get('annotation_reader');
44
        $generator = $this->getContainer()->get("tpg_extjs.generator");
45
        $outputLocation = false;
46
        if ($input->getOption("output")) {
47
            if (is_dir($input->getOption("output"))) {
48
                $outputLocation = realpath($input->getOption("output"));
49
            } else {
50
                if (is_dir(dirname($input->getOption("output")))) {
51
                    if (!$this->canWriteFile($input, $output, $input->getOption("output"))) {
52
                        exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
53
                    }
54
                    file_put_contents($input->getOption("output"), '');
55
                    $outputLocation = realpath($input->getOption("output"));
56
                } else {
57
                    $output->writeln("Invalid output directory");
58
                    exit(1);
0 ignored issues
show
Coding Style Compatibility introduced by
The method execute() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
59
                }
60
            }
61
        }
62
        $metadata = $this->getMetadata($input, $output, $outputLocation === false);
63
        foreach ($metadata->getMetadata() as $classMetadata) {
64
            /** @var ClassMetadata $classMetadata */
65
            $classMetadata->reflClass = new \ReflectionClass($classMetadata->name);
66
            if ($reader->getClassAnnotation(
67
                    $classMetadata->getReflectionClass(),
68
                    'Tpg\ExtjsBundle\Annotation\Model'
69
                ) !== null
70
            ) {
71
                if ($outputLocation) {
72
                    if (is_dir($outputLocation)) {
73
                        $baseDir = $outputLocation;
74
                        foreach (explode("\\", $classMetadata->namespace) as $dir) {
75
                            @mkdir($baseDir.DIRECTORY_SEPARATOR.$dir);
76
                            $baseDir .= DIRECTORY_SEPARATOR.$dir;
77
                        }
78
                        $fileName = $baseDir.DIRECTORY_SEPARATOR.substr(
79
                                $classMetadata->name,
80
                                strlen($classMetadata->namespace) + 1
81
                            ).".js";
82
                        if (!$this->canWriteFile($input, $output, $fileName)) {
83
                            continue;
84
                        }
85
                        file_put_contents(
86
                            $fileName,
87
                            $generator->generateMarkupForEntity($classMetadata->name)
88
                        );
89
                        $output->writeln("Generated $fileName");
90
                    } else {
91
                        file_put_contents(
92
                            $outputLocation,
93
                            $generator->generateMarkupForEntity($classMetadata->name),
94
                            FILE_APPEND
95
                        );
96
                        $output->writeln("Appending to $outputLocation");
97
                    }
98
                } else {
99
                    $output->write($generator->generateMarkupForEntity($classMetadata->name));
100
                }
101
            }
102
        }
103
    }
104
105
    /**
106
     * Returning ClassMetadata
107
     *
108
     * @param InputInterface $input An InputInterface instance
109
     * @param OutputInterface $output An OutputInterface instance
110
     * @param bool $displayStatus Displaying process messages
111
     *
112
     * @return ClassMetadataCollection
113
     */
114
    protected function getMetadata(InputInterface $input, OutputInterface $output, $displayStatus)
115
    {
116
        $manager = new DisconnectedMetadataFactory($this->getContainer()->get('doctrine'));
117
        try {
118
            $bundle = $this->getContainer()->get("kernel")->getBundle($input->getArgument('name'));
119
            if ($displayStatus) {
120
                $output->writeln(sprintf('Generating entities for bundle "<info>%s</info>"', $bundle->getName()));
121
            }
122
            $metadata = $manager->getBundleMetadata($bundle);
123
        } catch (\InvalidArgumentException $e) {
124
            $name = strtr($input->getArgument('name'), '/', '\\');
125
126
            if (false !== $pos = strpos($name, ':')) {
127
                $name = $this->getContainer()->get('doctrine')
128
                        ->getAliasNamespace(substr($name, 0, $pos)).'\\'.substr($name, $pos + 1);
129
            }
130
131
            if (class_exists($name)) {
132
                if ($displayStatus) {
133
                    $output->writeln(sprintf('Generating entity "<info>%s</info>"', $name));
134
                }
135
                $metadata = $manager->getClassMetadata($name, $input->getOption('path'));
136
            } else {
137
                if ($displayStatus) {
138
                    $output->writeln(sprintf('Generating entities for namespace "<info>%s</info>"', $name));
139
                }
140
                $metadata = $manager->getNamespaceMetadata($name, $input->getOption('path'));
141
            }
142
        }
143
144
        return $metadata;
145
    }
146
147
    protected function canWriteFile(InputInterface $input, OutputInterface $output, $fileName)
148
    {
149
        if (!$input->getOption("overwrite") && file_exists($fileName)) {
150
            $dialog = $this->getHelperSet()->get('dialog');
151
            $result = $dialog->askConfirmation(
152
                $output,
153
                '<question>'.$fileName.' already exist, overwrite?</question>',
154
                false
155
            );
156
            if (!$result) {
157
                $output->writeln("Skipping $fileName");
158
            }
159
160
            return $result;
161
        } else {
162
            return true;
163
        }
164
    }
165
}