MassUpdate   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 79
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B massAction() 0 46 9
A __construct() 0 11 1
1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Controller\Adminhtml\Order;
10
11
use Magento\Backend\App\Action\Context;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action\Context was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Model\...tion\AbstractCollection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Magento\Sales\Api\OrderManagementInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Api\OrderManagementInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Magento\Sales\Model\Order;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Model\Reso...Order\CollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Magento\Ui\Component\MassAction\Filter;
0 ignored issues
show
Bug introduced by
The type Magento\Ui\Component\MassAction\Filter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * Class MassDelete.
20
 */
21
class MassUpdate extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Controller...rder\AbstractMassAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
{
23
    /*
24
     * @var Order Management
25
     */
26
    protected $orderManagement;
27
28
    /*
29
     * @param Context
30
     * @param Filter
31
     * @param CollectionFactory
32
     * @param OrderManagementInterface
33
     */
34
    public function __construct(
35
        Context $context,
36
        Filter $filter,
37
        CollectionFactory $collectionFactory,
38
        OrderManagementInterface $orderManagement,
39
        Order $order
40
    ) {
41
        parent::__construct($context, $filter);
42
        $this->collectionFactory = $collectionFactory;
0 ignored issues
show
Bug Best Practice introduced by
The property collectionFactory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
        $this->orderManagement = $orderManagement;
44
        $this->order = $order;
0 ignored issues
show
Bug Best Practice introduced by
The property order does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
45
    }
46
47
    /*
48
     * Mass Action
49
     *
50
     * @param collection
51
     *
52
     * @return Url
0 ignored issues
show
Bug introduced by
The type Moip\Magento2\Controller\Adminhtml\Order\Url was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
     */
54
    protected function massAction(AbstractCollection $collection)
55
    {
56
        $countUpdate = 0;
57
        $countNotUpdate = 0;
58
59
        foreach ($collection->getItems() as $order) {
60
            if (!$order->getEntityId()) {
61
                continue;
62
            }
63
64
            $loadedOrder = $this->order->load($order->getEntityId());
65
66
            if ($loadedOrder->canFetchPaymentReviewUpdate()) {
67
                $payment = $loadedOrder->getPayment();
68
                $transactionId = $payment->getLastTransId();
69
                $method = $payment->getMethodInstance();
70
71
                try {
72
                    $method->fetchTransactionInfo($payment, $transactionId);
73
                    $payment->getOrder()->save();
74
                    $state = $payment->getOrder()->getState();
75
                    if ($state === 'processing') {
76
                        $countUpdate++;
77
                    }
78
                    $countNotUpdate++;
79
                } catch (\Exception $exc) {
80
                    $countNotUpdate++;
81
                }
82
            } elseif (!$loadedOrder->canFetchPaymentReviewUpdate()) {
83
                $countNotUpdate++;
84
            }
85
86
            continue;
87
        }
88
89
        if ($countUpdate) {
90
            $this->messageManager->addSuccess(__('%1 payments have been updated.', $countUpdate));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
            $this->messageManager->addSuccess(/** @scrutinizer ignore-call */ __('%1 payments have been updated.', $countUpdate));
Loading history...
91
        }
92
        if ($countNotUpdate) {
93
            $this->messageManager->addWarning(__('%1 payments have not yet been updated.', $countNotUpdate));
94
        }
95
96
        $resultRedirect = $this->resultRedirectFactory->create();
97
        $resultRedirect->setPath($this->getComponentRefererUrl());
98
99
        return $resultRedirect;
100
    }
101
}
102