StatusUpdateOrderCc   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 81
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A execute() 0 41 5
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\Cron;
10
11
use Magento\Payment\Model\Method\Logger;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\Method\Logger 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\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...
13
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...
14
use Moip\Magento2\Gateway\Config\ConfigCc;
15
16
/*
17
 * Class StatusUpdateOrderCc
18
 */
19
class StatusUpdateOrderCc
20
{
21
    /**
22
     * @var Logger
23
     */
24
    protected $logger;
25
26
    /**
27
     * @var Order
28
     */
29
    protected $order;
30
31
    /**
32
     * @var collectionFactory
33
     */
34
    protected $collectionFactory;
35
36
    /**
37
     * @var ConfigCc
38
     */
39
    protected $configCc;
40
41
    /*
42
     * @param order
43
     * @param logger
44
     * @param ConfigCc
45
     * @param collectionFactory
46
     */
47
    public function __construct(
48
        Order $order,
49
        Logger $logger,
50
        ConfigCc $configCc,
51
        CollectionFactory $collectionFactory
52
    ) {
53
        $this->order = $order;
54
        $this->logger = $logger;
55
        $this->configCc = $configCc;
56
        $this->collectionFactory = $collectionFactory;
57
    }
58
59
    public function execute()
60
    {
61
        $orders = $this->collectionFactory->create()
62
        ->addFieldToFilter('status', [
63
            'in' => [
64
                Order::STATE_PAYMENT_REVIEW,
65
            ],
66
        ]);
67
68
        $orders->getSelect()
69
                ->join(
70
                    ['sop' => 'sales_order_payment'],
71
                    'main_table.entity_id = sop.parent_id',
72
                    ['method']
73
                )
74
                ->where('sop.method = ?', ConfigCc::METHOD);
75
76
        foreach ($orders as $order) {
77
            if (!$order->getEntityId()) {
78
                continue;
79
            }
80
            $loadedOrder = $this->order->load($order->getEntityId());
81
82
            if ($loadedOrder->canFetchPaymentReviewUpdate()) {
83
                $payment = $loadedOrder->getPayment();
84
85
                try {
86
                    $payment->update(true);
87
                    $loadedOrder->save();
88
                    $this->logger->debug([
89
                        'cron'      => 'cc',
90
                        'type'      => 'updateStatus',
91
                        'order'     => $loadedOrder->getIncrementId(),
92
                        'new_state' => $loadedOrder->getStatus(),
93
                    ]);
94
                } catch (\Exception $exc) {
95
                    $this->logger->debug([
96
                        'cron'  => 'cc',
97
                        'type'  => 'updateStatus',
98
                        'order' => $loadedOrder->getIncrementId(),
99
                        'error' => $exc->getMessage(),
100
                    ]);
101
                }
102
            }
103
        }
104
    }
105
}
106