Issues (68)

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.

app/src/Console/Commands/GenerateModelCommand.php (3 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 App\Console\Commands;
4
5
use Illuminate\Database\Capsule\Manager as Capsule;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\Question;
10
use App\Common\Helper;
11
use App\Console\Traits\CodeGenerate;
12
13
/**
14
 * GenerateModelCommand
15
 */
16
class GenerateModelCommand extends Command
17
{
18
    use CodeGenerate;
19
20
    /**
21
     * Configuration of command
22
     */
23
    protected function configure()
24
    {
25
        $this
26
            ->setName('generate:model')
27
            ->setDescription('Command for generate model')
28
        ;
29
    }
30
31
    /**
32
     * Execute method of command
33
     *
34
     * @param InputInterface $input
35
     * @param OutputInterface $output
36
     *
37
     * @return void
38
     * @throws \Exception
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $output->writeln(['<comment>Welcome to the model generator</comment>']);
43
44
        $helper    = $this->getHelper('question');
45
        $question  = new Question('<info>Please enter table name: </info>');
46
        $tableName = $helper->ask($input, $output, $question);
47
48
        $table = Capsule::schema()->getColumnListing($tableName);
49
        if (count($table) === 0) {
50
            $output->writeln([sprintf('<comment>Not found table `%s`</comment>', $tableName)]);
51
            return;
52
        }
53
54
        $columns = [];
55 View Code Duplication
        foreach ($table as $columnName) {
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...
56
            $columnType = Capsule::schema()->getColumnType($tableName, $columnName);
57
            $columns[] = [
58
                'name' => $columnName,
59
                'type' => $columnType !== 'datetime' ? $columnType : '\Carbon\Carbon',
60
            ];
61
        }
62
63
        $modelName = substr($tableName, 0, -1);
64
        $className = Helper::underscoreToCamelCase($modelName, true);
65
        $baseName  = $className.'.php';
66
        $path      = $this->getPath($baseName, MODELS_PATH);
67
68
        $placeHolders = [
69
            '<class>',
70
            '<tableName>',
71
            '<phpdoc>',
72
            '<fillable>',
73
        ];
74
        $replacements = [
75
            $className,
76
            strtolower($tableName),
77
            $this->generatePhpDoc($columns),
78
            $this->generateFillable($columns),
79
        ];
80
81
        $this->generateCode($placeHolders, $replacements, 'ModelTemplate.tpl', $path);
82
83
        $output->writeln(sprintf('Generated new model class to "<info>%s</info>"', realpath($path)));
84
85
        return;
86
    }
87
88
    /**
89
     * @param array $columns
90
     * @return string
91
     */
92 View Code Duplication
    private function generatePhpDoc($columns)
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...
93
    {
94
        $phpdoc = [];
95
        foreach ($columns as $column) {
96
            $phpdoc[] = sprintf(" * @property %s $%s", $column['type'], $column['name']);
97
        };
98
99
        return implode("\n", $phpdoc);
100
    }
101
102
    /**
103
     * @param array $columns
104
     * @return string
105
     */
106 View Code Duplication
    private function generateFillable($columns)
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...
107
    {
108
        $fillable = [];
109
        foreach ($columns as $column) {
110
            $fillable[] = sprintf("        '%s',", $column['name']);
111
        };
112
113
        return implode("\n", $fillable);
114
    }
115
}
116