Issues (10)

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/Commands/SetAutoIncrementCommand.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 Sausin\DBSetAutoIncrement\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Facades\Config;
8
use Sausin\DBSetAutoIncrement\DatabaseInfo;
9
use Sausin\DBSetAutoIncrement\GetAttribute;
10
use Sausin\DBSetAutoIncrement\UpdateAttribute;
11
12
class SetAutoIncrementCommand extends Command
13
{
14
    use DatabaseInfo;
15
    use GetAttribute;
16
    use UpdateAttribute;
17
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'db:set-auto-increment
24
                            {--tables=* : The table(s) for which auto increment should be set}
25
                            {--value= : The auto increment value to be set}';
26
27
    /**
28
     * The console command description.
29
     *
30
     * @var string
31
     */
32
    protected $description = 'Set auto increment for database table(s)';
33
34
    /** @var array */
35
    protected $skipTables;
36
37
    /** @var array */
38
    protected $onlyTables;
39
40
    /** @var string */
41
    protected $mode;
42
43
    /** @var string */
44
    protected $driver;
45
46
    /** @var int */
47
    protected $autoIncrement;
48
49
    /** @var array */
50
    protected $supportedDrivers = ['mysql', 'sqlite'];
51
52
    /**
53
     * The name of the queue the job should be sent to.
54
     *
55
     * @var string|null
56
     */
57
    public $queue = 'monitoring';
58
59
    /**
60
     * Create the event listener.
61
     *
62
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
63
     */
64
    public function __construct()
65
    {
66
        parent::__construct();
67
68
        $this->mode = Config::get('auto-increment.mode', 'skip');
69
        $this->skipTables = Config::get('auto-increment.skipTables', ['migrations']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Faca...', array('migrations')) of type * is incompatible with the declared type array of property $skipTables.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
70
        $this->onlyTables = Config::get('auto-increment.onlyTables', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Faca...t.onlyTables', array()) of type * is incompatible with the declared type array of property $onlyTables.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
71
    }
72
73
    /**
74
     * Execute the console command.
75
     *
76
     * @return mixed
77
     */
78
    public function handle()
79
    {
80
        $this->autoIncrement = $this->option('value') ?? Config::get('auto-increment.autoIncrement', 100001);
81
82
        if (! $this->isDatabaseCompatible()) {
83
            $this->info("Database {$this->driver} not supported");
84
85
            return;
86
        }
87
88
        $driver = ucfirst($this->driver);
89
90
        if ($this->option('tables')) {
91
            $this->{"update{$driver}Tables"}(collect($this->option('tables')));
92
93
            $this->info('Specified tables have been updated');
94
95
            return;
96
        }
97
98
        $tables = collect([]);
99
100
        if ($this->mode === 'only') {
101
            $tables = collect($this->onlyTables);
102
        }
103
104
        if ($this->mode === 'skip') {
105
            $tables = collect($this->getTableList())->reject(function ($value) {
106
                return in_array($value, $this->skipTables, true);
107
            });
108
        }
109
110
        $this->{"update{$driver}Tables"}($tables);
111
        $this->info('Tables have been updated as per config');
112
    }
113
114
    /**
115
     * Update AUTO INCREMENT value in mysql tables.
116
     *
117
     * @param  Collection $tables
118
     * @return void
119
     */
120 View Code Duplication
    protected function updateMysqlTables(Collection $tables): void
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...
121
    {
122
        $tables->filter(function ($table) {
123
            return $this->getAutoIncrement('Mysql', $table) < $this->autoIncrement;
124
        })->map(function ($table) {
125
            $this->updateAutoIncrement('Mysql', $table);
126
        });
127
    }
128
129
    /**
130
     * Update AUTO INCREMENT value in sqlite tables.
131
     *
132
     * @param  Collection $tables
133
     * @return void
134
     */
135 View Code Duplication
    protected function updateSqliteTables(Collection $tables): void
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...
136
    {
137
        // the auto increment value is reduced by 1 as SQLITE uses it in this way
138
        $this->autoIncrement--;
139
140
        $tables->filter(function ($table) {
141
            return $this->getAutoIncrement('Sqlite', $table) < $this->autoIncrement;
142
        })->map(function ($table) {
143
            $this->updateAutoIncrement('Sqlite', $table);
144
        });
145
    }
146
}
147