PaymentRelease   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 124
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A _isAllowed() 0 3 1
B execute() 0 34 6
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\SplitExampleMagento\Controller\Adminhtml\Order;
10
11
use Getnet\PaymentMagento\Model\Console\Command\Marketplace\PaymentRelease as ModelPaymentRelease;
0 ignored issues
show
Bug introduced by
The type Getnet\PaymentMagento\Mo...ketplace\PaymentRelease 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 Getnet\SplitExampleMagento\Helper\Data;
13
use Magento\Backend\App\Action;
14
use Magento\Backend\App\Action\Context;
15
use Magento\Framework\Controller\ResultFactory;
16
use Magento\Framework\Controller\ResultInterface;
17
use Magento\Framework\Message\ManagerInterface;
18
use Magento\Framework\Serialize\Serializer\Json;
19
20
/**
21
 * Class Payment Release - Generate Payment Release.
22
 */
23
class PaymentRelease extends Action
24
{
25
    /**
26
     * Authorization level of a basic admin session.
27
     *
28
     * @see _isAllowed()
29
     */
30
    public const ADMIN_RESOURCE = 'Getnet_SplitExampleMagento::payment_release';
31
32
    /**
33
     * @var ResultFactory
34
     */
35
    protected $resultResultFactory;
36
37
    /**
38
     * @var Json
39
     */
40
    protected $json;
41
42
    /**
43
     * @var Data
44
     */
45
    protected $helper;
46
47
    /**
48
     * @var ModelPaymentRelease
49
     */
50
    protected $modelPaymentRelease;
51
52
    /**
53
     * @var ManagerInterface
54
     */
55
    protected $messageManager;
56
57
    /**
58
     * @var \Magento\Framework\Stdlib\DateTime\DateTime
59
     */
60
    protected $date;
61
62
    /**
63
     * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
64
     */
65
    protected $timezone;
66
67
    /**
68
     * @param Context                                              $context
69
     * @param ResultFactory                                        $resultResultFactory
70
     * @param Json                                                 $json
71
     * @param Data                                                 $helper
72
     * @param ModelPaymentRelease                                  $modelPaymentRelease
73
     * @param ManagerInterface                                     $messageManager
74
     * @param \Magento\Framework\Stdlib\DateTime\DateTime          $date
75
     * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
76
     */
77
    public function __construct(
78
        Context $context,
79
        ResultFactory $resultResultFactory,
80
        Json $json,
81
        Data $helper,
82
        ModelPaymentRelease $modelPaymentRelease,
83
        ManagerInterface $messageManager,
84
        \Magento\Framework\Stdlib\DateTime\DateTime $date,
85
        \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
86
    ) {
87
        $this->resultResultFactory = $resultResultFactory;
88
        $this->json = $json;
89
        $this->helper = $helper;
90
        $this->modelPaymentRelease = $modelPaymentRelease;
91
        $this->messageManager = $messageManager;
92
        $this->date = $date;
93
        $this->timezone = $timezone;
94
        parent::__construct($context);
95
    }
96
97
    /**
98
     * ACL.
99
     *
100
     * @return bool
101
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
102
     */
103
    protected function _isAllowed()
104
    {
105
        return $this->_authorization->isAllowed(self::ADMIN_RESOURCE);
106
    }
107
108
    /**
109
     * Execute.
110
     *
111
     * @return ResultInterface
112
     */
113
    public function execute()
114
    {
115
        $orderId = (int) $this->getRequest()->getParam('order_id');
116
        $days = $this->helper->getDaysOfRelease();
117
        $days = $days ? $days : 1;
118
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
119
        $date = new \DateTime();
120
        $date->add(new \DateInterval('P'.$days.'D'));
121
        $date = $date->format('Y-m-d\TH:i:s\Z');
122
123
        try {
124
            /** @var $modelPaymentRelease modelPaymentRelease */
125
            $modelPaymentRelease = $this->modelPaymentRelease->createPaymentRelease($orderId, $date);
126
            if ($modelPaymentRelease->getSuccess()) {
127
                $this->messageManager->addSuccess('Payment released');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Messag...Interface::addSuccess() has been deprecated: 100.1.0 ( Ignorable by Annotation )

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

127
                /** @scrutinizer ignore-deprecated */ $this->messageManager->addSuccess('Payment released');

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...
128
            }
129
130
            if ($modelPaymentRelease->getMessage()) {
131
                foreach ($modelPaymentRelease->getDetails() as $message) {
132
                    $messageInfo = __(
133
                        'Error: %1, description: %2',
134
                        $message['error_code'],
135
                        $message['description_detail']
136
                    );
137
                    $this->messageManager->addError($messageInfo);
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Messag...erInterface::addError() has been deprecated: 100.1.0 ( Ignorable by Annotation )

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

137
                    /** @scrutinizer ignore-deprecated */ $this->messageManager->addError($messageInfo);

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...
138
                }
139
            }
140
        } catch (\Exception $exc) {
141
            $this->messageManager->addError($exc->getMessage());
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Messag...erInterface::addError() has been deprecated: 100.1.0 ( Ignorable by Annotation )

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

141
            /** @scrutinizer ignore-deprecated */ $this->messageManager->addError($exc->getMessage());

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...
142
        }
143
144
        $resultRedirect->setUrl($this->_redirect->getRefererUrl());
0 ignored issues
show
Bug introduced by
The method setUrl() does not exist on Magento\Framework\Controller\ResultInterface. It seems like you code against a sub-type of Magento\Framework\Controller\ResultInterface such as Magento\Framework\Controller\Result\Redirect. ( Ignorable by Annotation )

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

144
        $resultRedirect->/** @scrutinizer ignore-call */ 
145
                         setUrl($this->_redirect->getRefererUrl());
Loading history...
145
146
        return $resultRedirect;
147
    }
148
}
149