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.

Model/Observer/OrderPaymentPayObserver.php (2 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 Stockbase\Integration\Model\Observer;
3
4
use Magento\Framework\Event\Observer;
5
use Magento\Framework\Event\ObserverInterface;
6
use Magento\Framework\ObjectManagerInterface;
7
use Magento\Sales\Api\Data\OrderInterface;
8
use Magento\Sales\Api\Data\OrderItemInterface;
9
use Magento\Sales\Api\OrderRepositoryInterface;
10
use Stockbase\Integration\StockbaseApi\Client\StockbaseClientFactory;
11
use Stockbase\Integration\Model\Config\StockbaseConfiguration;
12
use Stockbase\Integration\Model\Inventory\StockbaseStockManagement;
13
use Stockbase\Integration\Model\OrderedItem as StockbaseOrderedItem;
14
use Stockbase\Integration\Model\StockItemReserve;
15
16
/**
17
 * Class OrderPaymentPayObserver
18
 */
19
class OrderPaymentPayObserver implements ObserverInterface
20
{
21
    /**
22
     * @var StockbaseConfiguration
23
     */
24
    private $stockbaseConfiguration;
25
26
    /**
27
     * @var StockbaseClientFactory
28
     */
29
    private $stockbaseClientFactory;
30
31
    /**
32
     * @var StockbaseStockManagement
33
     */
34
    private $stockbaseStockManagement;
35
36
    /**
37
     * @var ObjectManagerInterface
38
     */
39
    private $objectManager;
40
41
    /**
42
     * OrderPaymentPayObserver constructor.
43
     * @param StockbaseConfiguration   $stockbaseConfiguration
44
     * @param StockbaseStockManagement $stockbaseStockManagement
45
     * @param StockbaseClientFactory   $stockbaseClientFactory
46
     * @param ObjectManagerInterface   $objectManager
47
     */
48 3
    public function __construct(
49
        StockbaseConfiguration $stockbaseConfiguration,
50
        StockbaseStockManagement $stockbaseStockManagement,
51
        StockbaseClientFactory $stockbaseClientFactory,
52
        ObjectManagerInterface $objectManager
53
    ) {
54 3
        $this->stockbaseConfiguration = $stockbaseConfiguration;
55 3
        $this->stockbaseClientFactory = $stockbaseClientFactory;
56 3
        $this->stockbaseStockManagement = $stockbaseStockManagement;
57 3
        $this->objectManager = $objectManager;
58 3
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public function execute(Observer $observer)
64
    {
65 3
        if (!$this->stockbaseConfiguration->isModuleEnabled()) {
66 1
            return $this;
67
        }
68
69
        /** @var \Magento\Sales\Api\Data\InvoiceInterface $invoice */
70 2
        $invoice = $observer->getData('invoice');
71
72
        // since InvoiceInterface doesn't explicitly define getOrder(), we have to do this...
73 2
        if (\method_exists($invoice, 'getOrder')) {
74
            /** @var \Magento\Sales\Api\Data\OrderInterface $order */
75 2
            $order = $invoice->getOrder();
76
        } else {
77
            /** @var OrderRepositoryInterface $repository */
78
            $repository = $this->objectManager->get(OrderRepositoryInterface::class);
79
            $order = $repository->get($invoice->getOrderId());
80
        }
81
82 2
        $quoteItemIds = \array_map(function (OrderItemInterface $item) {
83 2
            return $item->getQuoteItemId();
84 2
        }, (array) $order->getAllItems());
85
86
        /** @var StockItemReserve[] $reservedStockbaseItems */
87 2
        $reservedStockbaseItems = $this->stockbaseStockManagement->getReserveForQuoteItem($quoteItemIds);
88
89 2
        if (empty($reservedStockbaseItems)) {
90 1
            return $this;
91
        }
92
93 1
        $client = $this->stockbaseClientFactory->create();
94 1
        $result = $client->createOrder($order, $reservedStockbaseItems);
0 ignored issues
show
$result 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...
95
96 1
        foreach ($reservedStockbaseItems as $reserve) {
97 1
            $this->addStatusHistoryComment($order, __(
98 1
                'Item with EAN "%1" (%2 pc.) has been ordered from Stockbase.',
99 1
                $reserve->getEan(),
100 1
                $reserve->getAmount()
101
            ));
102
            //$order->save();
103
104
            /** @var StockbaseOrderedItem $stockbaseOrderedItem */
105 1
            $stockbaseOrderedItem = $this->objectManager->create(StockbaseOrderedItem::class);
106 1
            $stockbaseOrderedItem->setOrderId($order->getId());
107 1
            $stockbaseOrderedItem->setOrderItemId($reserve->getOrderItemId());
108 1
            $stockbaseOrderedItem->setProductId($reserve->getProductId());
109 1
            $stockbaseOrderedItem->setEan($reserve->getEan());
110 1
            $stockbaseOrderedItem->setAmount($reserve->getAmount());
111 1
            $stockbaseOrderedItem->setCreatedAt((new \DateTime())->format('Y-m-d H:i:s'));
112 1
            $stockbaseOrderedItem->save();
113
114
            // Decrement local Stockbase stock amount
115 1
            $this->stockbaseStockManagement->updateStockAmount($reserve->getEan(), $reserve->getAmount(), '-');
116
117
            // Release the reserve
118 1
            $this->stockbaseStockManagement->releaseReserve($reserve);
119
120 1
            $this->addStatusHistoryComment($order, __(
121 1
                'Local Stockbase stock index for item with EAN "%1" has been updated.',
122 1
                $reserve->getEan()
123
            ));
124
            //$order->save();
125
        }
126
127 1
        return $this;
128
    }
129
130
    /**
131
     * Safe add status history comment.
132
     *
133
     * @param OrderInterface $order
134
     * @param string $comment
135
     * @param $status
136
     * @return void
137
     */
138 1
    private function addStatusHistoryComment(OrderInterface $order, string $comment, $status = false)
139
    {
140 1
        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...
141
            return;
142
        }
143
144 1
        $order->addStatusHistoryComment($comment, $status);
145 1
    }
146
}
147