Issues (18)

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/Traits/QueryBuilderTrait.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 Codexshaper\WooCommerce\PHP\Traits;
4
5
use Codexshaper\WooCommerce\PHP\WooCommerce;
6
7
trait QueryBuilderTrait
8
{
9
    /**
10
     * @var
11
     */
12
    protected $options = [];
13
    /**
14
     * @var
15
     */
16
    protected $where = [];
17
    /**
18
     * @var
19
     */
20
    protected $properties = [];
21
22
    /**
23
     * Retrieve all Items.
24
     *
25
     * @param array $options
26
     *
27
     * @return array
28
     */
29
    protected function all($options = [])
30
    {
31
        return WooCommerce::all($this->endpoint, $options);
0 ignored issues
show
The property endpoint does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
34
    /**
35
     * Retrieve single Item.
36
     *
37
     * @param int   $id
38
     * @param array $options
39
     *
40
     * @return object
41
     */
42
    protected function find($id, $options = [])
43
    {
44
        return WooCommerce::find("{$this->endpoint}/{$id}", $options);
45
    }
46
47
    /**
48
     * Create new Item.
49
     *
50
     * @param array $data
51
     *
52
     * @return object
53
     */
54
    protected function create($data)
55
    {
56
        return WooCommerce::create($this->endpoint, $data);
57
    }
58
59
    /**
60
     * Update Existing Item.
61
     *
62
     * @param int   $id
63
     * @param array $data
64
     *
65
     * @return object
66
     */
67
    protected function update($id, $data)
68
    {
69
        return WooCommerce::update("{$this->endpoint}/{$id}", $data);
70
    }
71
72
    /**
73
     * Destroy Item.
74
     *
75
     * @param int   $id
76
     * @param array $options
77
     *
78
     * @return object
79
     */
80
    protected function delete($id, $options = [])
81
    {
82
        return WooCommerce::delete("{$this->endpoint}/{$id}", $options);
83
    }
84
85
    /**
86
     * Batch Update.
87
     *
88
     * @param array $data
89
     *
90
     * @return object
91
     */
92
    protected function batch($data)
93
    {
94
        return WooCommerce::create("{$this->endpoint}/batch", $data);
95
    }
96
97
    /**
98
     * Retrieve data.
99
     *
100
     * @return array
101
     */
102
    protected function get()
103
    {
104
        return WooCommerce::all($this->endpoint, $this->options);
105
    }
106
107
    /**
108
     * Retrieve data.
109
     *
110
     * @return object
111
     */
112
    protected function first()
113
    {
114
        return $this->get()[0] ?? new \stdClass();
115
    }
116
117
    /**
118
     * Set options for woocommerce request.
119
     *
120
     * @param array $parameters
121
     *
122
     * @return object $this
123
     */
124
    protected function options($parameters)
125
    {
126
        if (!is_array($parameters)) {
127
            throw new \Exception('Options must be an array', 1);
128
        }
129
130
        if (empty($parameters)) {
131
            throw new \Exception('Options must be pass at least one element', 1);
132
        }
133
134
        foreach ($parameters as $key => $value) {
135
            $this->options[$key] = $value;
136
        }
137
138
        return $this;
139
    }
140
141
    /**
142
     * Join options for woocommerce request.
143
     *
144
     * @param array $parameters
145
     *
146
     * @return object $this
147
     */
148
    protected function where(...$parameters)
149
    {
150
        if (count($parameters) < 2 || count($parameters) > 3) {
151
            throw new \Exception('You can pass minimum 2 and maximum 3 paramneters');
152
        }
153
        $field = strtolower($parameters[0]);
154
        $value = count($parameters) == 3 ? $parameters[2] : $parameters[1];
155
156
        switch ($field) {
157
            case 'name': case 'title': case 'description':
158
                $this->options['search'] = $value;
159
                break;
160
            default:
161
                $this->options[$field] = $value;
162
                break;
163
        }
164
165
        return $this;
166
    }
167
168
    /**
169
     * Set order direction.
170
     *
171
     * @param string $name
172
     * @param string $direction
173
     *
174
     * @return object $this
175
     */
176
    protected function orderBy($name, $direction = 'desc')
177
    {
178
        $this->options['orderby'] = $name;
179
        $this->options['order'] = $direction;
180
181
        return $this;
182
    }
183
184
    /**
185
     * Paginate results.
186
     *
187
     * @param int $per_page
188
     * @param int $current_page
189
     *
190
     * @return array
191
     */
192
    protected function paginate($per_page, $current_page = 1)
193
    {
194
        try {
195
            $this->options['per_page'] = (int) $per_page;
196
197
            if ($current_page > 0) {
198
                $this->options['page'] = (int) $current_page;
199
            }
200
201
            $results = $this->get();
202
            $totalResults = WooCommerce::countResults();
203
            $totalPages = WooCommerce::countPages();
204
            $currentPage = WooCommerce::current();
205
            $previousPage = WooCommerce::previous();
206
            $nextPage = WooCommerce::next();
207
208
            $pagination = [
209
                'total_results' => $totalResults,
210
                'total_pages'   => $totalPages,
211
                'current_page'  => $currentPage,
212
                'previous_page' => $previousPage,
213
                'next_page'     => $nextPage,
214
                'first_page'    => 1,
215
                'last_page'     => $totalResults,
216
            ];
217
218
            $results['pagination'] = $pagination;
219
220
            return $results;
221
        } catch (\Exception $ex) {
222
            throw new \Exception($ex->getMessage(), 1);
223
        }
224
    }
225
226
    /**
227
     * Count all results.
228
     *
229
     * @return int
230
     */
231
    protected function count()
232
    {
233
        try {
234
            $results = WooCommerce::all($this->endpoint, $this->options);
0 ignored issues
show
$results is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
235
            $totalResults = WooCommerce::countResults();
236
237
            return $totalResults;
238
        } catch (\Exception $ex) {
239
            throw new \Exception($ex->getMessage(), 1);
240
        }
241
    }
242
243
    /**
244
     * Store data.
245
     *
246
     * @return array
247
     */
248
    public function save()
249
    {
250
        $this->results = WooCommerce::create($this->endpoint, $this->properties);
0 ignored issues
show
The property results does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
251
252
        return $this->results;
253
    }
254
}
255