Issues (18)

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/Repository/OrderRepository.php (8 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 LarsJanssen\IncrementDecrement\Repository;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class OrderRepository implements OrderRepositoryInterface
8
{
9
    /**
10
     * @var mixed
11
     */
12
    public $column;
13
14
    /**
15
     * OrderRepository constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->column = config('increment-decrement.order_column_name');
20
    }
21
22
    /**
23
     * @param Model $model
24
     *
25
     * @return bool
26
     */
27 View Code Duplication
    public function increment(Model $model)
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...
28
    {
29
        if ($model->{$this->column} != 1) {
30
            $model::where($this->column, $model->{$this->column} - 1)->increment($this->column);
31
            $model->decrement($this->column);
0 ignored issues
show
The method decrement() cannot be called from this context as it is declared protected in class Illuminate\Database\Eloquent\Model.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
32
33
            return true;
34
        }
35
36
        return $this->toLast($model);
37
    }
38
39
    /**
40
     * @param Model $model
41
     *
42
     * @return bool
43
     */
44 View Code Duplication
    public function decrement(Model $model)
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...
45
    {
46
        if ($model->{$this->column} != $this->count($model)) {
47
            $model::where($this->column, $model->{$this->column} + 1)->decrement($this->column);
48
            $model->increment($this->column);
0 ignored issues
show
The method increment() cannot be called from this context as it is declared protected in class Illuminate\Database\Eloquent\Model.

This check looks for access to methods that are not accessible from the current context.

If you need to make a method accessible to another context you can raise its visibility level in the defining class.

Loading history...
49
50
            return true;
51
        }
52
53
        return $this->toFirst($model);
54
    }
55
56
    /**
57
     * @param Model $model
58
     *
59
     * @return bool
60
     */
61
    public function delete(Model $model)
62
    {
63
        $toDecrement = $model::where($this->column, '>', $model->{$this->column})->get();
64
        if (count($toDecrement)) {
65
            $toDecrement->each->decrement($this->column);
66
            true;
67
        }
68
69
        return false;
70
    }
71
72
    /**
73
     * @param Model $model
74
     *
75
     * @return bool
76
     */
77
    public function toFirst(Model $model)
78
    {
79 View Code Duplication
        if ($model->{$this->column} != 1) {
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...
80
            $models = $model::where($this->column, '<', $model->{$this->column})->get();
81
            $models->each->increment($this->column);
82
            $model->{$this->column} = 1;
83
            $model->save();
84
85
            return true;
86
        }
87
88
        return false;
89
    }
90
91
    /**
92
     * @param Model $model
93
     *
94
     * @return bool
95
     */
96
    public function toLast(Model $model)
97
    {
98
        $last = $this->count($model);
99
100 View Code Duplication
        if ($last != $model->{$this->column}) {
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...
101
            $models = $model::where($this->column, '>', $model->{$this->column})->get();
102
            $models->each->decrement($this->column);
103
            $model->{$this->column} = $last;
104
            $model->save();
105
106
            return true;
107
        }
108
109
        return false;
110
    }
111
112
    /**
113
     * @param Model $model
114
     *
115
     * @return bool
116
     */
117
    public function toMiddle(Model $model)
118
    {
119
        $middle = number_format($this->count($model) / 2);
120
        $between = [$model->{$this->column}, $middle];
121
122
        if ($model->{$this->column} != $middle) {
123 View Code Duplication
            if ($model->{$this->column} > $middle) {
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...
124
                $result = $model::whereBetween($this->column, array_reverse($between))->get();
125
                $result->each->increment($this->column);
126
            }
127
128 View Code Duplication
            if ($model->{$this->column} < $middle) {
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...
129
                $result = $model::whereBetween($this->column, $between)->get();
130
                $result->each->decrement($this->column);
131
            }
132
133
            $model->{$this->column} = $middle;
134
            $model->save();
135
136
            return true;
137
        }
138
139
        return false;
140
    }
141
142
    /**
143
     * @param Model $model1
144
     * @param Model $model2
145
     *
146
     * @return bool
147
     */
148
    public function switchModels(Model $model1, Model $model2)
149
    {
150
        $temp = $model1->{$this->column};
151
        $model1->{$this->column} = $model2->{$this->column};
152
        $model2->{$this->column} = $temp;
153
154
        $model1->save();
155
        $model2->save();
156
157
        return true;
158
    }
159
160
    /**
161
     * @param Model $model
162
     * @param $index1
163
     * @param $index2
164
     *
165
     * @return bool
166
     */
167
    public function switchIndexes(Model $model, $index1, $index2)
168
    {
169
        $model1 = $model::where($this->column, $index1)->first();
170
        $model2 = $model::where($this->column, $index2)->first();
171
172
        return $this->switchModels($model1, $model2);
173
    }
174
175
    /**
176
     * @param Model $model
177
     *
178
     * @return mixed
179
     */
180
    public function count(Model $model)
181
    {
182
        return $model::count();
183
    }
184
}
185