Issues (101)

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.

src/Commands/MigrationCommand.php (5 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 Consigliere\Components\Commands;
4
5
use Illuminate\Support\Str;
6
use Consigliere\Components\Support\Migrations\NameParser;
7
use Consigliere\Components\Support\Migrations\SchemaParser;
8
use Consigliere\Components\Support\Stub;
9
use Consigliere\Components\Traits\ComponentCommandTrait;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
13
class MigrationCommand extends Command
14
{
15
    use ComponentCommandTrait;
16
17
    /**
18
     * The console command name.
19
     *
20
     * @var string
21
     */
22
    protected $name = 'component:make-migration';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Generate a new migration for the specified component.';
30
31
    /**
32
     * Get the console command arguments.
33
     *
34
     * @return array
35
     */
36
    protected function getArguments()
37
    {
38
        return [
39
            ['name', InputArgument::REQUIRED, 'The migration name will be created.'],
40
            ['component', InputArgument::OPTIONAL, 'The name of component will be created.'],
41
        ];
42
    }
43
44
    /**
45
     * Get the console command options.
46
     *
47
     * @return array
48
     */
49
    protected function getOptions()
50
    {
51
        return [
52
            ['fields', null, InputOption::VALUE_OPTIONAL, 'The specified fields table.', null],
53
            ['plain', null, InputOption::VALUE_NONE, 'Create plain migration.'],
54
        ];
55
    }
56
57
    /**
58
     * Get schema parser.
59
     *
60
     * @return SchemaParser
61
     */
62
    public function getSchemaParser()
63
    {
64
        return new SchemaParser($this->option('fields'));
0 ignored issues
show
It seems like $this->option('fields') targeting Illuminate\Console\Command::option() can also be of type array; however, Consigliere\Components\S...maParser::__construct() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
65
    }
66
67
    /**
68
     * @throws \InvalidArgumentException
69
     *
70
     * @return mixed
71
     */
72
    protected function getTemplateContents()
73
    {
74
        $parser = new NameParser($this->argument('name'));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Consigliere\Components\S...meParser::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
75
76
        if ($parser->isCreate()) {
77
            return Stub::create('/migration/create.stub', [
78
                'class'  => $this->getClass(),
79
                'table'  => $parser->getTableName(),
80
                'fields' => $this->getSchemaParser()->render(),
81
            ]);
82 View Code Duplication
        } elseif ($parser->isAdd()) {
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...
83
            return Stub::create('/migration/add.stub', [
84
                'class'       => $this->getClass(),
85
                'table'       => $parser->getTableName(),
86
                'fields_up'   => $this->getSchemaParser()->up(),
87
                'fields_down' => $this->getSchemaParser()->down(),
88
            ]);
89
        } elseif ($parser->isDelete()) {
90
            return Stub::create('/migration/delete.stub', [
91
                'class'       => $this->getClass(),
92
                'table'       => $parser->getTableName(),
93
                'fields_down' => $this->getSchemaParser()->up(),
94
                'fields_up'   => $this->getSchemaParser()->down(),
95
            ]);
96 View Code Duplication
        } elseif ($parser->isDrop()) {
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...
97
            return Stub::create('/migration/drop.stub', [
98
                'class'  => $this->getClass(),
99
                'table'  => $parser->getTableName(),
100
                'fields' => $this->getSchemaParser()->render(),
101
            ]);
102
        }
103
104
        return Stub::create('/migration/plain.stub', [
105
            'class' => $this->getClass(),
106
        ]);
107
    }
108
109
    /**
110
     * @return mixed
111
     */
112
    protected function getDestinationFilePath()
113
    {
114
        $path = $this->laravel['components']->getComponentPath($this->getComponentName());
115
116
        $generatorPath = $this->laravel['components']->config('paths.generator.migration');
117
118
        return $path . $generatorPath . '/' . $this->getFileName() . '.php';
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    private function getFileName()
125
    {
126
        return date('Y_m_d_His_') . $this->getSchemaName();
127
    }
128
129
    /**
130
     * @return array|string
131
     */
132
    private function getSchemaName()
133
    {
134
        return $this->argument('name');
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    private function getClassName()
141
    {
142
        return Str::studly($this->argument('name'));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
143
    }
144
145
    public function getClass()
146
    {
147
        return $this->getClassName();
148
    }
149
150
    /**
151
     * Run the command.
152
     */
153
    public function fire()
154
    {
155
        parent::fire();
156
157
        if (app()->environment() === 'testing') {
158
            return;
159
        }
160
        $this->call('optimize');
161
    }
162
}
163