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/Cray.php (6 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
use Illuminate\Support\Str;
6
use JunaidQadirB\Cray\Console\Contracts\GeneratorCommand;
7
8
class Cray extends GeneratorCommand
9
{
10
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'cray';
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'cray
23
    {name : Model name. Controller, factory, migration, views will be based on this name.}
24
    {--views-dir= : Place views in a sub-directory under the views directory. It can be any nested directory structure}
25
    {--controller-dir= : Place controller in a sub-directory under the Http/Controllers directory. It can be any nested directory structure}
26
    {--stubs-dir= : Specify a custom stubs directory}
27
    {--no-views : Do not create view files for the model}
28
    {--no-migration : Do not create a migration for the model}
29
    {--no-factory : Do not create a factory for the model}
30
    ';
31
32
    /**
33
     * The console command description.
34
     *
35
     * @var string
36
     */
37
    protected $description = 'Scaffold a nearly complete boilerplate CRUD pages for the specified Model';
38
39
    /**
40
     * Create a new command instance.
41
     *
42
     */
43
    /*    public function __construct()
44
        {
45
            parent::__construct();
46
        }*/
47
48
    /**
49
     * Execute the console command.
50
     *
51
     * @return mixed
52
     */
53
    public function handle()
54
    {
55
        /**
56
         * Steps
57
         * - Generate Model
58
         * - Generate Factory
59
         * - Generate Migration
60
         * - Generate Controller
61
         * - Generate Requests
62
         * - Generate Views
63
         *
64
         */
65
        $this->type = 'Model';
66
67
        if (!$this->option('no-factory')) {
68
            $this->createFactory();
69
        }
70
71
        if (!$this->option('no-migration')) {
72
            $this->createMigration();
73
        }
74
        $this->createController();
75
76
        if (!$this->option('no-views')) {
77
            $this->createViews();
78
        }
79
80
        $this->type = 'Request';
81
82
        $this->createRequest('Store');
83
84
        $this->createRequest('Update');
85
86
87
    }
88
89
    /**
90
     * Create a model factory for the model.
91
     *
92
     * @return void
93
     */
94 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...
95
    {
96
        $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...
97
98
        $this->call('cray:factory', [
99
            'name' => "{$factory}Factory",
100
            '--model' => $this->argument('name'),
101
        ]);
102
    }
103
104
    /**
105
     * Create a migration file for the model.
106
     *
107
     * @return void
108
     */
109 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...
110
    {
111
        $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...
112
113
        $this->call('cray:migration', [
114
            'name' => "create_{$table}_table",
115
            '--create' => $table,
116
        ]);
117
    }
118
119
    /**
120
     * Create a controller for the model.
121
     *
122
     * @return void
123
     */
124
    protected function createController()
125
    {
126
127
        $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...
128
129
        $modelName = $this->qualifyClass($this->getNameInput());
130
131
        $args = [
132
            'name' => "{$controller}Controller",
133
            '--model' => $modelName,
134
        ];
135
136
        $viewsDir = $this->option('views-dir');
137
        if ($viewsDir) {
138
            $args['--views-dir'] = $viewsDir;
139
        }
140
141
        $controllerDir = $this->option('controller-dir');
142
        if ($controllerDir) {
143
            $args['--controller-dir'] = $controllerDir;
144
        }
145
146
        $this->call('cray:controller', $args);
147
    }
148
149
    protected function createViews()
150
    {
151
        $name = $this->argument('name');
152
        $args = [
153
            'name' => $name,
154
            '--all' => true,
155
        ];
156
157
        $dir = $this->option('views-dir');
158
        if ($dir) {
159
            $args['--dir'] = $dir;
160
        }
161
162
        $stub = $this->option('stubs-dir');
163
        if ($stub) {
164
            $args['--stubs'] = $stub;
165
        }
166
        $this->call('cray:view', $args);
167
168
169
    }
170
171
    /**
172
     * Create a controller for the model.
173
     *
174
     * @param string $requestType
175
     *
176
     * @return void
177
     */
178
    protected function createRequest($requestType = 'Store')
179
    {
180
        $model = 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...
181
        $name = "{$model}{$requestType}Request";
182
        $this->call('cray:request', [
183
            'name' => $name,
184
            '--model' => $model,
185
            '--type' => Str::slug($requestType),
186
        ]);
187
    }
188
189
    /**
190
     * Get the stub file for the generator.
191
     *
192
     * @return string
193
     */
194
    protected function getStub()
195
    {
196
        return config('cray.stubs_dir') . '/' . Str::slug($this->type) . '.stub';
197
    }
198
199
    /**
200
     * Get the default namespace for the class.
201
     *
202
     * @param string $rootNamespace
203
     *
204
     * @return string
205
     */
206
    protected function getDefaultNamespace($rootNamespace)
207
    {
208
        switch ($this->type) {
209
            case 'Request':
210
                return $rootNamespace . '\Http\Requests';
211
        }
212
213
        return $rootNamespace;
214
    }
215
}
216