Passed
Branch [email protected] (aae97d)
by Bruno
10:40
created

FetchTransactionOrderWallet::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 4
dl 0
loc 10
rs 10
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Cron;
10
11
use Getnet\PaymentMagento\Gateway\Config\ConfigWallet;
12
use Magento\Payment\Model\Method\Logger;
13
use Magento\Sales\Model\Order;
14
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
15
16
/*
17
 * Class Fetch Transaction Order Wallet - Cron fetch order
18
 */
19
class FetchTransactionOrderWallet
20
{
21
    /**
22
     * @var Logger
23
     */
24
    protected $logger;
25
26
    /**
27
     * @var Order
28
     */
29
    protected $order;
30
31
    /**
32
     * @var ConfigWallet
33
     */
34
    protected $configWallet;
35
36
    /**
37
     * @var CollectionFactory
38
     */
39
    protected $collectionFactory;
40
41
    /**
42
     * @param Order             $order
43
     * @param Logger            $logger
44
     * @param ConfigWallet      $configWallet
45
     * @param CollectionFactory $collectionFactory
46
     */
47
    public function __construct(
48
        Order $order,
49
        Logger $logger,
50
        ConfigWallet $configWallet,
51
        CollectionFactory $collectionFactory
52
    ) {
53
        $this->order = $order;
54
        $this->logger = $logger;
55
        $this->configWallet = $configWallet;
56
        $this->collectionFactory = $collectionFactory;
57
    }
58
59
    /**
60
     * Execute.
61
     *
62
     * @return void
63
     */
64
    public function execute()
65
    {
66
        $orders = $this->collectionFactory->create()
67
        ->addFieldToFilter('state', [
68
            'in' => [
69
                Order::STATE_NEW,
70
            ],
71
        ]);
72
73
        $orders->getSelect()
74
                ->join(
75
                    ['sop' => 'sales_order_payment'],
0 ignored issues
show
Unused Code introduced by
The call to Magento\Framework\DB\Select::join() has too many arguments starting with array('sop' => 'sales_order_payment'). ( Ignorable by Annotation )

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

75
                ->/** @scrutinizer ignore-call */ join(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
76
                    'main_table.entity_id = sop.parent_id',
77
                    ['method']
78
                )
79
                ->where('sop.method = ?', ConfigWallet::METHOD);
80
81
        foreach ($orders as $order) {
82
            if (!$order->getEntityId()) {
83
                continue;
84
            }
85
            $loadedOrder = $this->order->load($order->getEntityId());
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Model\AbstractModel::load() has been deprecated: 100.1.0 because entities must not be responsible for their own loading. Service contracts should persist entities. Use resource model "load" or collections to implement service contract model loading operations. ( Ignorable by Annotation )

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

85
            $loadedOrder = /** @scrutinizer ignore-deprecated */ $this->order->load($order->getEntityId());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
86
            $payment = $loadedOrder->getPayment();
87
            $payment->update();
88
            $this->logger->debug([
89
                'cron'   => 'FetchTransactionOrderWallet',
90
                'type'   => ConfigWallet::METHOD,
91
                'order'  => $loadedOrder->getIncrementId(),
92
                'status' => $loadedOrder->getStatus(),
93
            ]);
94
        }
95
    }
96
}
97