Issues (1092)

Model/Plugins/CreditmemoService.php (5 issues)

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 - 2018 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\Model\Plugins;
28
29
use Magento\Sales\Model\Service\CreditmemoService as CreditmemoServiceOriginal;
0 ignored issues
show
The type Magento\Sales\Model\Service\CreditmemoService 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\Sales\Api\Data\CreditmemoInterface;
0 ignored issues
show
The type Magento\Sales\Api\Data\CreditmemoInterface 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
use Magento\Framework\Exception\LocalizedException;
0 ignored issues
show
The type Magento\Framework\Exception\LocalizedException 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...
32
use Payone\Core\Model\Api\Request\Debit;
33
34
class CreditmemoService
35
{
36
    /**
37
     * Checkout session model
38
     *
39
     * @var \Magento\Checkout\Model\Session
0 ignored issues
show
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...
40
     */
41
    protected $checkoutSession;
42
43
    /**
44
     * API-log resource model
45
     *
46
     * @var \Payone\Core\Model\ResourceModel\ApiLog
47
     */
48
    protected $apiLog;
49
50
    /**
51
     * Constructor
52
     *
53
     * @param \Magento\Checkout\Model\Session $checkoutSession
54
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
55
     */
56
    public function __construct(
57
        \Magento\Checkout\Model\Session $checkoutSession,
58
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog
59
    ) {
60
        $this->checkoutSession = $checkoutSession;
61
        $this->apiLog = $apiLog;
62
    }
63
64
    /**
65
     * @param  CreditmemoServiceOriginal $subject
66
     * @param  callable                  $proceed
67
     * @param  CreditmemoInterface       $creditmemo
68
     * @param  bool                      $offlineRequested
69
     * @return CreditmemoInterface
70
     * @throws LocalizedException|\Exception
71
     */
72
    public function aroundRefund(
73
        CreditmemoServiceOriginal $subject,
0 ignored issues
show
The parameter $subject is not used and could be removed. ( Ignorable by Annotation )

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

73
        /** @scrutinizer ignore-unused */ CreditmemoServiceOriginal $subject,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
        callable $proceed,
75
        CreditmemoInterface $creditmemo,
76
        $offlineRequested = false
77
    ) {
78
        try {
79
            $return = $proceed($creditmemo, $offlineRequested);
80
        } catch(\Exception $ex) {
81
            $aRequest = $this->checkoutSession->getPayoneDebitRequest();
82
            if (is_array($aRequest) && !empty($aRequest)) {
83
                $aResponse = $this->checkoutSession->getPayoneDebitResponse();
84
                $sOrderId = $this->checkoutSession->getPayoneDebitOrderId();
85
86
                // Rewrite the log-entry after it was rolled back in the db-transaction
87
                $this->apiLog->addApiLogEntry($aRequest, $aResponse, $aResponse['status'], $sOrderId);
88
            }
89
            $this->checkoutSession->unsPayoneDebitRequest();
90
            $this->checkoutSession->unsPayoneDebitResponse();
91
            $this->checkoutSession->unsPayoneDebitOrderId();
92
            throw $ex;
93
        }
94
        return $return;
95
    }
96
}