Issues (24)

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/Endpoint/Order.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
namespace Loevgaard\Dandomain\Api\Endpoint;
3
4
use Assert\Assert;
5
6
class Order extends Endpoint
7
{
8
    /**
9
     * @param \DateTimeInterface $dateStart
10
     * @param \DateTimeInterface $dateEnd
11
     * @param int|null $orderStateId
12
     * @return int
13
     */
14
    public function countByModifiedInterval(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd, int $orderStateId = null) : int
15
    {
16
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart must be before $dateEnd');
17
        Assert::thatNullOr($orderStateId)->integer('$orderStateId must be an integer');
18
19
        $q = sprintf(
20
            '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/CountByModifiedInterval?start=%s&end=%s',
21
            $dateStart->format('Y-m-d\TH:i:s'),
22
            $dateEnd->format('Y-m-d\TH:i:s')
23
        );
24
25
        if ($orderStateId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $orderStateId of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
26
            $q .= sprintf('&orderstateid=%d', $orderStateId);
27
        }
28
29
        return (int)$this->master->doRequest('GET', $q);
30
    }
31
32
    /**
33
     * @param array|\stdClass $order
34
     * @return array
35
     */
36
    public function createOrder($order) : array
37
    {
38
        return (array)$this->master->doRequest('POST', '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}', $order);
39
    }
40
41
    /**
42
     * @param \DateTimeInterface $dateStart
43
     * @param \DateTimeInterface $dateEnd
44
     * @return array
45
     */
46
    public function getOrders(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd) : array
47
    {
48
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart must be before $dateEnd');
49
50
        return (array)$this->master->doRequest(
51
            'GET',
52
            sprintf(
53
                '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/GetByDateInterval?start=%s&end=%s',
54
                $dateStart->format('Y-m-d\TH:i:s'),
55
                $dateEnd->format('Y-m-d\TH:i:s')
56
            )
57
        );
58
    }
59
60
    /**
61
     * @param int $orderId
62
     * @return array
63
     */
64
    public function getOrder(int $orderId) : array
65
    {
66
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
67
68
        return (array)$this->master->doRequest('GET', sprintf('/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/%d', $orderId));
69
    }
70
71
    /**
72
     * Deletes an order
73
     *
74
     * @param int $orderId
75
     * @return bool
76
     */
77
    public function deleteOrder(int $orderId) : bool
78
    {
79
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
80
81
        return (bool)$this->master->doRequest('DELETE', sprintf('/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/%d', $orderId));
82
    }
83
84
    /**
85
     * @param int $orderId
86
     * @return bool
87
     */
88
    public function completeOrder(int $orderId) : bool
89
    {
90
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
91
92
        return (bool)$this->master->doRequest(
93
            'PUT',
94
            sprintf('/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/CompleteOrder/%d', $orderId)
95
        );
96
    }
97
98
    /**
99
     * @param int $customerNumber
100
     * @return array
101
     */
102
    public function getOrdersByCustomerNumber(int $customerNumber) : array
103
    {
104
        Assert::that($customerNumber)->greaterThan(0, 'The $customerNumber has to be positive');
105
106
        return (array)$this->master->doRequest(
107
            'GET',
108
            sprintf('/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/GetByCustomerNumber/%d', $customerNumber)
109
        );
110
    }
111
112
    /**
113
     * @param \DateTimeInterface $dateStart
114
     * @param \DateTimeInterface $dateEnd
115
     * @param int $page
116
     * @param int $pageSize
117
     * @param int|null $orderStateId
118
     * @return array
119
     */
120
    public function getOrdersInModifiedInterval(\DateTimeInterface $dateStart, \DateTimeInterface $dateEnd, int $page = 1, int $pageSize = 100, int $orderStateId = null) : array
121
    {
122
        Assert::that($dateStart)->lessThan($dateEnd, '$dateStart must be before $dateEnd');
123
        Assert::that($page)->greaterThan(0, 'The $page has to be positive');
124
        Assert::that($pageSize)->greaterThan(0, 'The $pageSize has to be positive');
125
        Assert::thatNullOr($orderStateId)->integer('$orderStateId must be an integer');
126
127
        $q = sprintf(
128
            '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/GetByModifiedInterval?start=%s&end=%s&pageIndex=%d&pageSize=%d',
129
            $dateStart->format('Y-m-d\TH:i:s'),
130
            $dateEnd->format('Y-m-d\TH:i:s'),
131
            $page,
132
            $pageSize
133
        );
134
135
        if ($orderStateId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $orderStateId of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
136
            $q .= sprintf('&orderstateid=%d', $orderStateId);
137
        }
138
139
        return (array)$this->master->doRequest('GET', $q);
140
    }
141
142
    /**
143
     * @return array
144
     */
145
    public function getOrderStates() : array
146
    {
147
        return (array)$this->master->doRequest('GET', '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/OrderStates');
148
    }
149
150
    /**
151
     * @param int $orderId
152
     * @param string $comment
153
     * @return bool
154
     */
155 View Code Duplication
    public function setOrderComment(int $orderId, string $comment) : bool
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...
156
    {
157
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
158
        Assert::that($comment)->minLength(1, 'The length of $comment has to be > 0');
159
160
        return (bool)$this->master->doRequest(
161
            'PUT',
162
            sprintf(
163
                '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/SetOrderComment/%d?comment=%s',
164
                $orderId,
165
                rawurlencode($comment)
166
            )
167
        );
168
    }
169
170
    /**
171
     * @param int $orderId
172
     * @param int $orderState
173
     * @return bool
174
     */
175 View Code Duplication
    public function setOrderState(int $orderId, int $orderState) : bool
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...
176
    {
177
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
178
        Assert::that($orderState)->greaterThan(0, 'The $orderState has to be positive');
179
180
        return (bool)$this->master->doRequest(
181
            'PUT',
182
            sprintf('/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/SetOrderState/%d/%d', $orderId, $orderState)
183
        );
184
    }
185
186
    /**
187
     * @param int $orderId
188
     * @param string $trackingNumber
189
     * @return bool
190
     */
191 View Code Duplication
    public function setTrackNumber(int $orderId, string $trackingNumber) : bool
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...
192
    {
193
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
194
        Assert::that($trackingNumber)->minLength(1, 'The length of $trackingNumber has to be > 0');
195
196
        return (bool)$this->master->doRequest(
197
            'PUT',
198
            sprintf(
199
                '/admin/WEBAPI/Endpoints/v1_0/OrderService/{KEY}/SetTrackNumber/%d?tracknumber=%s',
200
                $orderId,
201
                rawurlencode($trackingNumber)
202
            )
203
        );
204
    }
205
206
    /******************
207
     * Helper methods *
208
     *****************/
209
    /**
210
     * Will copy an order based on the order id
211
     * If the $orderLines is empty, it will also copy the order lines
212
     * If the $orderState is > 0, the method will update the order state
213
     * If $completeOrder is true, the method will also complete the order, otherwise it will be marked as incomplete by default
214
     * Returns the new order
215
     *
216
     * @param int $orderId
217
     * @param array $orderLines
218
     * @param int $orderState
219
     * @param boolean $completeOrder
220
     * @return array
221
     */
222
    public function copyOrder(int $orderId, array $orderLines = [], int $orderState = 0, bool $completeOrder = true) : array
223
    {
224
        Assert::that($orderId)->greaterThan(0, 'The $orderId has to be positive');
225
226
        $order = $this->getOrder($orderId);
227
228
        $data = [
229
            'siteId'            => $order['siteId'],
230
            'altDeliveryInfo'   => null,
231
            'currencyCode'      => $order['currencyCode'],
232
            'customerId'        => $order['customerInfo']['id'],
233
            'paymentId'         => $order['paymentInfo']['id'],
234
            'shippingId'        => $order['shippingInfo']['id'],
235
            'orderLines'        => $order['orderLines']
236
        ];
237
238
        if (!empty($orderLines)) {
239
            $data['orderLines'] = $orderLines;
240
        }
241
242
        $newOrder = $this->createOrder($data);
243
        $newOrderId = (int)$newOrder['id'];
244
245
        if ($completeOrder) {
246
            $this->completeOrder($newOrderId);
247
        }
248
249
        if ($orderState) {
250
            $this->setOrderState($newOrderId, $orderState);
251
        }
252
253
        return $newOrder;
254
    }
255
}
256