Passed
Push — master ( 36f687...04ba37 )
by
unknown
02:40 queued 29s
created

Returned::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 11
rs 10
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\Onepage;
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
use Magento\Framework\App\Request\Http;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Request\Http 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...
31
32
/**
33
 * Controller for handling return from payment provider
34
 */
35
class Returned extends \Payone\Core\Controller\ExternalAction
36
{
37
    /**
38
     * Checkout session
39
     *
40
     * @var \Magento\Checkout\Model\Session
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\Session 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...
41
     */
42
    protected $checkoutSession;
43
44
    /**
45
     * PAYONE substitute order handler
46
     *
47
     * @var \Payone\Core\Model\Handler\SubstituteOrder
48
     */
49
    protected $substituteOrder;
50
51
    /**
52
     * PAYONE database helper
53
     *
54
     * @var \Payone\Core\Helper\Database
55
     */
56
    protected $databaseHelper;
57
58
    /**
59
     * Constructor
60
     *
61
     * @param \Magento\Framework\App\Action\Context         $context
62
     * @param \Magento\Framework\Data\Form\FormKey          $formKey
63
     * @param \Magento\Checkout\Model\Session               $checkoutSession
64
     * @param \Payone\Core\Model\Handler\SubstituteOrder    $substituteOrder
65
     * @param \Payone\Core\Helper\Database                  $databaseHelper
66
     */
67
    public function __construct(
68
        \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...
69
        \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...
70
        \Magento\Checkout\Model\Session $checkoutSession,
71
        \Payone\Core\Model\Handler\SubstituteOrder $substituteOrder,
72
        \Payone\Core\Helper\Database $databaseHelper
73
    ) {
74
        parent::__construct($context, $formKey);
75
        $this->checkoutSession = $checkoutSession;
76
        $this->substituteOrder = $substituteOrder;
77
        $this->databaseHelper = $databaseHelper;
78
    }
79
80
    /**
81
     * Get canceled order.
82
     * Return order if found.
83
     * Return false if not found or not canceled
84
     *
85
     * @return bool|Order
86
     */
87
    protected function getCanceledOrder()
88
    {
89
        $order = $this->checkoutSession->getLastRealOrder();
90
        if (!$order->getId() && !empty($this->getRequest()->getParam('incrementId'))) {
91
            $sSubstituteIncrementId = $this->databaseHelper->getSubstituteOrderIncrementId($this->getRequest()->getParam('incrementId'));
92
            if (!empty($sSubstituteIncrementId)) {
93
                $order->loadByIncrementId($sSubstituteIncrementId);
94
                $this->substituteOrder->updateCheckoutSession($order);
95
                return false;
96
            } else {
97
                $order->loadByIncrementId($this->getRequest()->getParam('incrementId'));
98
            }
99
        }
100
101
        if ($order->getStatus() == Order::STATE_CANCELED) {
102
            return $order;
103
        }
104
        return false;
105
    }
106
107
    /**
108
     * Redirect to success page
109
     * Do whatever processing is needed after successful return from payment-provider
110
     *
111
     * @return void
112
     */
113
    public function execute()
114
    {
115
        $this->checkoutSession->unsPayoneCustomerIsRedirected();
116
117
        $canceledOrder = $this->getCanceledOrder();
118
        if ($canceledOrder !== false) {
119
            $this->substituteOrder->createSubstituteOrder($canceledOrder);
0 ignored issues
show
Bug introduced by
It seems like $canceledOrder can also be of type true; however, parameter $canceledOrder of Payone\Core\Model\Handle...createSubstituteOrder() does only seem to accept Magento\Sales\Model\Order, maybe add an additional type check? ( Ignorable by Annotation )

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

119
            $this->substituteOrder->createSubstituteOrder(/** @scrutinizer ignore-type */ $canceledOrder);
Loading history...
120
        }
121
122
        $this->_redirect($this->_url->getUrl('checkout/onepage/success'));
123
    }
124
}
125