Issues (2687)

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/GeneratorCommand/EntityFromDbGenerator.php (9 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
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Command\GeneratorCommand;
26
27
use Doctrine\Common\Util\Inflector;
28
use Doctrine\ORM\Mapping\ClassMetadataInfo;
29
use Doctrine\ORM\Mapping\Driver\DatabaseDriver;
30
use Doctrine\ORM\Tools\Console\MetadataFilter;
31
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
32
use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
33
use Symfony\Component\Finder\Finder;
34
35
class EntityFromDbGenerator extends AbstractPluginGenerator
0 ignored issues
show
Missing class doc comment
Loading history...
36
{
37
38
    /**
39
     * テーブルリスト
40
     *
41
     * @var array
42
     */
43
    private $tableList = null;
44
45 View Code Duplication
    protected function getHeader()
0 ignored issues
show
This method seems to be duplicated in 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...
46
    {
47
        $this->output->writeln('------------------------------------------------------');
48
        $this->output->writeln('---Plugin Generator for Entity');
49
        $this->output->writeln('---[*]You need to create table schema first.');
50
        $this->output->writeln('---[*]You can exit from Console Application, by typing '.self::STOP_PROCESS.' instead of typing another word.');
51
        $this->output->writeln('------------------------------------------------------');
52
        $this->output->writeln('');
53
    }
54
55 View Code Duplication
    protected function initFieldSet()
0 ignored issues
show
This method seems to be duplicated in 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...
56
    {
57
        $this->paramList = array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
58
            'pluginCode' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
59
                'no' => 1,
60
                'label' => '[+]Plugin Code: ',
61
                'value' => null,
62
                'name' => '[+]Please enter Plugin Code (First letter is uppercase alphabet only. alphabet and numbers are allowed.)',
63
                'validation' => array(
64
                    'isRequired' => true,
65
                    'isNotCode' => $this->getPluginCodes(),
66
                )
67
            ),
68
            'tableList' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
69
                'no' => 2,
70
                'label' => '[+]Table name: ',
71
                'value' => array(),
72
                'name' => '[+]Please enter table name',
73
                'validation' => array(
74
                    'isRequired' => false,
75
                    'inArray' => $this->getTableList(),
76
                )
77
            ),
78
            'supportFlag' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
79
                'no' => 3,
80
                'label' => '[+]Old version support: ',
81
                'value' => null,
82
                'name' => '[+]Do you want to support old versions too? [y/n]',
83
                'show' => array(1 => 'Yes', 0 => 'No'),
84
                'validation' => array(
85
                    'isRequired' => true,
86
                    'choice' => array('y' => 1, 'n' => 0),
87
                )
88
            )
89
        );
90
    }
91
92
    /**
93
     * プラグイン用テーブル一覧(plg_xxxx)の取得
94
     *
95
     * @return array
96
     */
97
    protected function getTableList()
98
    {
99
        if ($this->tableList === null) {
100
            $this->tableList = array();
101
            $SchemaManager = $this->app['orm.em']->getConnection()->getSchemaManager();
102
            foreach ($SchemaManager->listTables() as $Table) {
103
                $tableName = $Table->getName();
104
                if (strpos($tableName, self::PLUGIN_PREFIX) !== 0) {
105
                    continue;
106
                }
107
                $this->tableList[$tableName] = $tableName;
108
            }
109
        }
110
111
        return $this->tableList;
112
    }
113
114
    protected function start()
115
    {
116
        $pluginCode = $this->paramList['pluginCode']['value'];
117
118
        $codes = $this->getPluginCodes();
119
        if (!in_array($pluginCode, $codes)) {
120
            $this->exitGenerator('<error>This plugin code does not exist.</error>');
121
122
            return;
123
        }
124
125
        $fsList = array(
126
            'dir' => array(),
127
            'file' => array(),
128
        );
129
130
        $tableList = $this->paramList['tableList']['value'];
131
        $codePath = $this->app['config']['root_dir'].'/app/Plugin/'.$pluginCode;
132
133
        $dirList = array('Entity', 'Repository', 'Resource', 'Resource/doctrine', 'Resource/doctrine/migration');
134 View Code Duplication
        foreach ($dirList as $dirName) {
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...
135
            $dirPath = $codePath.'/'.$dirName;
136
            if (!is_dir($dirPath)) {
137
                mkdir($dirPath);
138
            }
139
            if (is_dir($dirPath)) {
140
                $fsList['dir'][$dirPath] = true;
141
            } else {
142
                $fsList['dir'][$dirPath] = false;
143
            }
144
        }
145
146
        $doctrinePath = $codePath.'/Resource/doctrine';
147
148
        if (count($tableList)) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
149
150
            // ymlファイルの作成
151
            $em = $this->app['orm.em'];
152
153
            $databaseDriver = new DatabaseDriver(
154
                $em->getConnection()->getSchemaManager()
155
            );
156
157
            $em->getConfiguration()->setMetadataDriverImpl(
158
                $databaseDriver
159
            );
160
161
            $databaseDriver->setNamespace('Plugin\\'.$pluginCode.'\\Entity\\');
162
163
            $cmf = new DisconnectedClassMetadataFactory();
164
            $cmf->setEntityManager($em);
165
            $metadatas = $cmf->getAllMetadata();
166
167
            $filters = array_map(function ($value) {
168
                return ucfirst(Inflector::camelize(str_replace('plg_', '', $value)));
169
            }, $tableList);
170
            $metadatas = MetadataFilter::filter($metadatas, $filters);
171
172
            $cme = new ClassMetadataExporter();
173
            $exporter = $cme->getExporter('yml', $doctrinePath);
174
175
            /** @var ClassMetadataInfo $class */
176
            foreach ($metadatas as $class) {
177
                $class->name = str_replace('Plg', '', $class->name);
178
                $class->rootEntityName = str_replace('Plg', '', $class->rootEntityName);
179
                $name = explode('\\', $class->name);
180
                $class->customRepositoryClassName = 'Plugin\\'.$pluginCode.'\\Repository\\'.$name[count($name) - 1].'Repository';
181
                $class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
182
            }
183
184
            $exporter->setMetadata($metadatas);
185
            $exporter->export();
186
187
            $finder = new Finder();
188
            $finder->files()->depth('== 0');
189
            $files = $finder->in($doctrinePath);
190
191
            foreach ($files as $item) {
192
                $fsList['file'][$item->getRealPath()] = true;
193
            }
194
195
            // Entity、Repositoryファイルの作成
196
            $this->generateEntities($metadatas, $fsList);
197
198
            // migrationファイルの作成
199
            $this->generateMigration($metadatas, $fsList, $pluginCode, $codePath);
200
201
            // 完了メッセージ
202
            $this->completeMessage($fsList);
203
        }
204
205
    }
206
207
}
208