Issues (52)

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.

StockbaseApi/Client/StockbaseClient.php (1 issue)

Labels
Severity

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
4
namespace Stockbase\Integration\StockbaseApi\Client;
5
6
use Magento\Sales\Api\Data\OrderItemInterface;
7
use Webmozart\Assert\Assert;
8
use DivideBV\PHPDivideIQ\DivideIQ;
9
use Magento\Sales\Api\Data\OrderInterface;
10
use Stockbase\Integration\Model\Config\StockbaseConfiguration;
11
use Stockbase\Integration\Model\StockItemReserve;
12
13
/**
14
 * Stockbase API client.
15
 */
16
class StockbaseClient
17
{
18
    const STOCKBASE_STOCK_ENDPOINT = 'stockbase_stock';
19
    const STOCKBASE_IMAGES_ENDPOINT = 'stockbase_images';
20
    const STOCKBASE_ORDER_REQUEST_ENDPOINT = 'stockbase_orderrequest';
21
    
22
    /**
23
     * @var DivideIQ
24
     */
25
    private $divideIqClient;
26
    
27
    /**
28
     * @var StockbaseConfiguration
29
     */
30
    private $stockbaseConfiguration;
31
32
    /**
33
     * StockbaseClient constructor.
34
     * @param DivideIQ               $divideIqClient
35
     * @param StockbaseConfiguration $stockbaseConfiguration
36
     */
37 4
    public function __construct(
38
        DivideIQ $divideIqClient,
39
        StockbaseConfiguration $stockbaseConfiguration
40
    ) {
41 4
        $this->divideIqClient = $divideIqClient;
42 4
        $this->stockbaseConfiguration = $stockbaseConfiguration;
43 4
    }
44
45
    /**
46
     * Gets current Stockbase stock state.
47
     *
48
     * @param \DateTime|null $since
49
     * @param \DateTime|null $until
50
     * @return object
51
     * @throws \Exception
52
     */
53 1
    public function getStock(\DateTime $since = null, \DateTime $until = null)
54
    {
55 1
        $data = [];
56 1
        if ($since !== null) {
57 1
            $data['Since'] = $since->getTimestamp();
58
        }
59 1
        if ($until !== null) {
60 1
            $data['Until'] = $until->getTimestamp();
61
        }
62
        
63 1
        return $this->divideIqClient->request(self::STOCKBASE_STOCK_ENDPOINT, $data);
64
    }
65
66
    /**
67
     * Gets images for specified EANs.
68
     *
69
     * @param string[] $eans
70
     * @return object
71
     * @throws \Exception
72
     */
73 1
    public function getImages(array $eans)
74
    {
75 1
        Assert::allNumeric($eans);
76
        
77
        $data = [
78 1
            'ean' => implode(',', $eans),
79
        ];
80
        
81 1
        return $this->divideIqClient->request(self::STOCKBASE_IMAGES_ENDPOINT, $data);
82
    }
83
84
    /**
85
     * Downloads a file using current client configuration and saves it at the specified destination.
86
     *
87
     * @param string|\GuzzleHttp\Url                             $uri         File URI.
88
     * @param string|resource|\GuzzleHttp\Stream\StreamInterface $destination Destination where the file should be saved to.
89
     * @return null
90
     */
91
    public function downloadImage($uri, $destination)
92
    {
93
        return $this->divideIqClient->download($uri, $destination);
94
    }
95
96
    /**
97
     * Creates an order on Stockbase from reserved items for specified Magento order.
98
     *
99
     * @param OrderInterface     $order
100
     * @param StockItemReserve[] $reservedStockbaseItems
101
     * @return object
102
     * @throws \Exception
103
     */
104 2
    public function createOrder(OrderInterface $order, array $reservedStockbaseItems)
105
    {
106 2
        $orderPrefix = $this->stockbaseConfiguration->getOrderPrefix();
107 2
        $shippingAddress = $order->getShippingAddress();
108 2
        $now = new \DateTime('now', new \DateTimeZone('UTC'));
109 2
        $orderLines = [];
110
111 2
        $orderLineNumber = 0;
112 2
        foreach ($reservedStockbaseItems as $reserve) {
113 2
            $orderLineNumber++;
114
            $orderLineData = [
115 2
                'Number' => $orderLineNumber, // Number starting from 1
116 2
                'EAN' => $reserve->getEan(),
117 2
                'Amount' => (int) $reserve->getAmount(),
118
            ];
119
            
120
            /** @var OrderItemInterface $orderItem */
121 2
            $orderItem = $this->_getOrderItemById($order, $reserve->getOrderItemId());
122 2
            if ($orderItem && $orderItem->getRowTotal() !== null) {
123 2
                $orderLineData['Price'] = $orderItem->getRowTotal();
124
            }
125 2
            $orderLines[] = $orderLineData;
126
        }
127
128
        $orderHeader = [
129 2
            'OrderNumber' => $orderPrefix.'#'.$order->getRealOrderId(),
130 2
            'TimeStamp' => $now->format('Y-m-d h:i:s'),
131 2
            'Attention' => $order->getCustomerNote() ? $order->getCustomerNote() : ' ',
132
        ];
133
        
134
        $orderDelivery = [
135
            'Person' => [
136 2
                'FirstName' => $shippingAddress->getFirstname(),
137 2
                'Surname' => $shippingAddress->getLastname(),
138 2
                'Company' => $shippingAddress->getCompany() ?: ' ',
139
            ],
140
            'Address' => [
141 2
                'Street' => $shippingAddress->getStreetLine(1),
142 2
                'StreetNumber' => $shippingAddress->getStreetLine(2) ?: '-',
143 2
                'ZipCode' => $shippingAddress->getPostcode(),
144 2
                'City' => $shippingAddress->getCity(),
145 2
                'CountryCode' => $shippingAddress->getCountryId(),
146
            ],
147
        ];
148
149
        $orderRequest = [
150 2
            'OrderHeader' => $orderHeader,
151 2
            'OrderLines' => $orderLines,
152 2
            'OrderDelivery' => $orderDelivery,
153
        ];
154
155 2
        $response = $this->divideIqClient->request(self::STOCKBASE_ORDER_REQUEST_ENDPOINT, $orderRequest, 'POST');
156 2
        if ($response->{'StatusCode'} != 1) {
157 1
            $message = '';
158 1
            if (isset($response->{'Items'}) && is_array($response->{'Items'})) {
159 1
                foreach ($response->{'Items'} as $item) {
160 1
                    if ($item->{'StatusCode'} != 1) {
161 1
                        $message .= ' '.trim($item->{'ExceptionMessage'});
162
                    }
163
                }
164
            }
165 1
            throw new StockbaseClientException('Failed sending order to stockbase.'.$message);
166
        }
167
        
168 1
        return $response;
169
    }
170
    
171 2
    private function _getOrderItemById(OrderInterface $order, $orderItemId)
172
    {
173 2
        if ($order instanceof \Magento\Sales\Model\Order) {
0 ignored issues
show
The class Magento\Sales\Model\Order does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
174 2
            return $order->getItemById($orderItemId);
175
        } else {
176
            /** @var OrderItemInterface $orderItem */
177
            $orderItem = array_filter((array) $order->getItems(), function (OrderItemInterface $item) use ($orderItemId) {
178
                return $item->getItemId() == $orderItemId;
179
            });
180
            
181
            return reset($orderItem);
182
        }
183
    }
184
}
185