Issues (28)

Security Analysis    no request data  

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/Console/Commands/ModelMakeCommand.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 JunaidQadirB\Cray\Console\Commands;
4
5
6
use Illuminate\Support\Str;
7
use JunaidQadirB\Cray\Console\Contracts\GeneratorCommand;
8
use Symfony\Component\Console\Input\InputOption;
9
10
class ModelMakeCommand extends GeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'cray:model';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new Eloquent model class';
25
26
    /**
27
     * The type of class being generated.
28
     *
29
     * @var string
30
     */
31
    protected $type = 'Model';
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return void
37
     */
38
    public function handle()
39
    {
40
        if (parent::handle() === false && !$this->option('force')) {
41
            return;
42
        }
43
        if ($this->option('all')) {
44
            $this->input->setOption('factory', true);
45
            $this->input->setOption('migration', true);
46
            $this->input->setOption('controller', true);
47
            $this->input->setOption('resource', true);
48
        }
49
50
        if ($this->option('factory')) {
51
            $this->createFactory();
52
        }
53
54
        if ($this->option('migration')) {
55
            $this->createMigration();
56
        }
57
58
        if ($this->option('controller') || $this->option('resource')) {
59
            $this->createController();
60
        }
61
    }
62
63
    /**
64
     * Create a model factory for the model.
65
     *
66
     * @return void
67
     */
68 View Code Duplication
    protected function createFactory()
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...
69
    {
70
        $factory = Str::studly(class_basename($this->argument('name')));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Conce...ractsWithIO::argument() can also be of type array or null; however, class_basename() does only seem to accept string|object, 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...
71
72
        $this->call('cray:factory', [
73
            'name' => "{$factory}Factory",
74
            '--model' => $this->argument('name'),
75
        ]);
76
    }
77
78
    /**
79
     * Create a migration file for the model.
80
     *
81
     * @return void
82
     */
83 View Code Duplication
    protected function createMigration()
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...
84
    {
85
        $table = Str::plural(Str::snake(class_basename($this->argument('name'))));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Conce...ractsWithIO::argument() can also be of type array or null; however, class_basename() does only seem to accept string|object, 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...
86
87
        $this->call('cray:migration', [
88
            'name' => "create_{$table}_table",
89
            '--create' => $table,
90
        ]);
91
    }
92
93
    /**
94
     * Create a controller for the model.
95
     *
96
     * @return void
97
     */
98
    protected function createController()
99
    {
100
        $controller = Str::studly(class_basename($this->argument('name')));
0 ignored issues
show
It seems like $this->argument('name') targeting Illuminate\Console\Conce...ractsWithIO::argument() can also be of type array or null; however, class_basename() does only seem to accept string|object, 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...
101
102
        $modelName = $this->qualifyClass($this->getNameInput());
103
104
        $this->call('cray:controller', [
105
            'name' => "{$controller}Controller",
106
            '--model' => $this->option('resource') ? $modelName : null,
107
        ]);
108
    }
109
110
    /**
111
     * Get the stub file for the generator.
112
     *
113
     * @return string
114
     */
115
    protected function getStub()
116
    {
117
        if ($this->option('pivot')) {
118
            return config('cray.stubs_dir').'/pivot.model.stub';
119
        }
120
121
        return config('cray.stubs_dir').'/model.stub';
122
    }
123
124
    /**
125
     * Get the default namespace for the class.
126
     *
127
     * @param string $rootNamespace
128
     *
129
     * @return string
130
     */
131
    protected function getDefaultNamespace($rootNamespace)
132
    {
133
        return $rootNamespace;
134
    }
135
136
    /**
137
     * Get the console command options.
138
     *
139
     * @return array
140
     */
141
    protected function getOptions()
142
    {
143
        return [
144
            [
145
                'all',
146
                'a',
147
                InputOption::VALUE_NONE,
148
                'Generate a migration, factory, and resource controller for the model',
149
            ],
150
151
            ['controller', 'c', InputOption::VALUE_NONE, 'Create a new controller for the model'],
152
153
            ['factory', 'f', InputOption::VALUE_NONE, 'Create a new factory for the model'],
154
155
            ['force', null, InputOption::VALUE_NONE, 'Create the class even if the model already exists.'],
156
157
            ['migration', 'm', InputOption::VALUE_NONE, 'Create a new migration file for the model.'],
158
159
            [
160
                'pivot',
161
                'p',
162
                InputOption::VALUE_NONE,
163
                'Indicates if the generated model should be a custom intermediate table model.',
164
            ],
165
166
            [
167
                'resource',
168
                'r',
169
                InputOption::VALUE_NONE,
170
                'Indicates if the generated controller should be a resource controller.',
171
            ],
172
        ];
173
    }
174
}
175