Index::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 9
dl 0
loc 19
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Controller\Transactionstatus;
28
29
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...
30
31
/**
32
 * TransactionStatus receiver
33
 */
34
class Index extends \Payone\Core\Controller\ExternalAction
35
{
36
    /**
37
     * TransactionStatus model
38
     *
39
     * @var \Payone\Core\Model\ResourceModel\TransactionStatus
40
     */
41
    protected $transactionStatus;
42
43
    /**
44
     * PAYONE toolkit helper
45
     *
46
     * @var \Payone\Core\Helper\Toolkit
47
     */
48
    protected $toolkitHelper;
49
50
    /**
51
     * PAYONE environment helper
52
     *
53
     * @var \Payone\Core\Helper\Environment
54
     */
55
    protected $environmentHelper;
56
57
    /**
58
     * PAYONE order helper
59
     *
60
     * @var \Payone\Core\Helper\Order
61
     */
62
    protected $orderHelper;
63
64
    /**
65
     * TransactionStatus handler
66
     *
67
     * @var \Payone\Core\Model\Handler\TransactionStatus
68
     */
69
    protected $transactionStatusHandler;
70
71
    /**
72
     * Result factory for file-download
73
     *
74
     * @var \Magento\Framework\Controller\Result\RawFactory
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\RawFactory 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...
75
     */
76
    protected $resultRawFactory;
77
78
    /**
79
     * PAYONE substitute order handler
80
     *
81
     * @var \Payone\Core\Model\Handler\SubstituteOrder
82
     */
83
    protected $substituteOrder;
84
85
    /**
86
     * Constructor
87
     *
88
     * @param \Magento\Framework\App\Action\Context              $context
89
     * @param \Magento\Framework\Data\Form\FormKey               $formKey
90
     * @param \Payone\Core\Model\ResourceModel\TransactionStatus $transactionStatus
91
     * @param \Payone\Core\Helper\Toolkit                        $toolkitHelper
92
     * @param \Payone\Core\Helper\Environment                    $environmentHelper
93
     * @param \Payone\Core\Helper\Order                          $orderHelper
94
     * @param \Payone\Core\Model\Handler\TransactionStatus       $transactionStatusHandler,
95
     * @param \Magento\Framework\Controller\Result\RawFactory    $resultRawFactory
96
     * @param \Payone\Core\Model\Handler\SubstituteOrder         $substituteOrder
97
     */
98
    public function __construct(
99
        \Magento\Framework\App\Action\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\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...
100
        \Magento\Framework\Data\Form\FormKey $formKey,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Data\Form\FormKey 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...
101
        \Payone\Core\Model\ResourceModel\TransactionStatus $transactionStatus,
102
        \Payone\Core\Helper\Toolkit $toolkitHelper,
103
        \Payone\Core\Helper\Environment $environmentHelper,
104
        \Payone\Core\Helper\Order $orderHelper,
105
        \Payone\Core\Model\Handler\TransactionStatus $transactionStatusHandler,
106
        \Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
107
        \Payone\Core\Model\Handler\SubstituteOrder $substituteOrder
108
    ) {
109
        parent::__construct($context, $formKey);
110
        $this->transactionStatus = $transactionStatus;
111
        $this->toolkitHelper = $toolkitHelper;
112
        $this->environmentHelper = $environmentHelper;
113
        $this->orderHelper = $orderHelper;
114
        $this->transactionStatusHandler = $transactionStatusHandler;
115
        $this->resultRawFactory = $resultRawFactory;
116
        $this->substituteOrder = $substituteOrder;
117
    }
118
119
    /**
120
     * Return request parameter value
121
     *
122
     * @param  string $sKey
123
     * @return string
124
     */
125
    protected function getParam($sKey)
126
    {
127
        return $this->getRequest()->getParam($sKey, '');
128
    }
129
130
    /**
131
     * Return Post array
132
     *
133
     * @return array
134
     */
135
    protected function getPostArray()
136
    {
137
        return $this->getRequest()->getPostValue();
138
    }
139
140
    /**
141
     * Write the TransactionStatus to the database
142
     *
143
     * @param  Order $oOrder
144
     * @param  array $aRequest
145
     * @param  bool  $blWillBeHandled
146
     * @return void
147
     */
148
    protected function logTransactionStatus(Order $oOrder, $aRequest, $blWillBeHandled)
149
    {
150
        $this->transactionStatus->addTransactionLogEntry($aRequest, $oOrder, $blWillBeHandled);
151
    }
152
153
    /**
154
     * Main method for executing all needed actions for the incoming TransactionStatus
155
     *
156
     * @return string
157
     */
158
    protected function handleTransactionStatus()
159
    {
160
        if (!$this->environmentHelper->isRemoteIpValid()) {
161
            return 'Access denied';
162
        } elseif (!$this->toolkitHelper->isKeyValid($this->getParam('key'))) {
163
            return 'Key wrong or missing!';
164
        }
165
166
        $oOrder = $this->orderHelper->getOrderByTxid($this->getParam('txid'));
167
        if (!$oOrder) {
168
            return 'Order not found';
169
        }
170
171
        if ($this->getParam('txaction') == 'appointed' && $oOrder->getStatus() == 'canceled') {
172
            // order was canceled in checkout, probably due to browser-back-button usage -> create a new order for incoming payment
173
            $oOrder = $this->substituteOrder->createSubstituteOrder($oOrder, false);
174
        }
175
176
        $this->logTransactionStatus($oOrder, $this->getPostArray(), true);
177
178
        $this->transactionStatusHandler->handle($oOrder, $this->getPostArray());
179
180
        return 'TSOK';
181
    }
182
183
    /**
184
     * Executing TransactionStatus handling
185
     *
186
     * @return \Magento\Framework\Controller\Result\Raw
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\Raw 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...
187
     */
188
    public function execute()
189
    {
190
        $sOutput = $this->handleTransactionStatus();
191
192
        $oResultRaw = $this->resultRawFactory->create();
193
        $oResultRaw->setContents($sOutput);
194
        
195
        return $oResultRaw;
196
    }
197
}
198