Passed
Push — master ( 1b84e5...95ac4e )
by Florian
42s queued 12s
created

RatepayShowShopConfig::getRatepayShopConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
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 - 2020 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\Block\Adminhtml\Config\Form\Field;
28
29
/**
30
 * Admin-block for displaying Ratepay shop config
31
 */
32
class RatepayShowShopConfig extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
0 ignored issues
show
Bug introduced by
The type Magento\Config\Block\Sys...rray\AbstractFieldArray 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...
33
{
34
    /**
35
     * Template
36
     *
37
     * @var string
38
     */
39
    protected $_template = 'Payone_Core::system/config/form/field/ratepay_show_shop_config.phtml';
40
41
    /**
42
     * @var \Payone\Core\Helper\Ratepay
43
     */
44
    protected $ratepayHelper;
45
46
    /**
47
     * Ratepay profile resource model
48
     *
49
     * @var \Payone\Core\Model\ResourceModel\RatepayProfileConfig
50
     */
51
    protected $ratepayProfileResource;
52
53
    /**
54
     * Constructor
55
     *
56
     * @param \Magento\Backend\Block\Template\Context               $context
57
     * @param \Payone\Core\Helper\Ratepay                           $ratepayHelper
58
     * @param \Payone\Core\Model\ResourceModel\RatepayProfileConfig $ratepayProfileResource
59
     * @param array                                                 $data
60
     */
61
    public function __construct(
62
        \Magento\Backend\Block\Template\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Block\Template\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...
63
        \Payone\Core\Helper\Ratepay $ratepayHelper,
64
        \Payone\Core\Model\ResourceModel\RatepayProfileConfig $ratepayProfileResource,
65
        array $data = []
66
    ) {
67
        parent::__construct($context, $data);
68
        $this->ratepayHelper = $ratepayHelper;
69
        $this->ratepayProfileResource = $ratepayProfileResource;
70
    }
71
72
    /**
73
     * Initialise form fields
74
     *
75
     * @return void
76
     */
77
    protected function _construct()
78
    {
79
        $this->addColumn('txaction', ['label' => __('Transactionstatus-message')]);
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

79
        $this->addColumn('txaction', ['label' => /** @scrutinizer ignore-call */ __('Transactionstatus-message')]);
Loading history...
80
        $this->_addAfter = false;
0 ignored issues
show
Bug Best Practice introduced by
The property _addAfter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
81
        $this->_addButtonLabel = __('Add Minimum Qty');
0 ignored issues
show
Bug Best Practice introduced by
The property _addButtonLabel does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
82
        parent::_construct();
83
    }
84
85
    /**
86
     * Returns current payment method
87
     *
88
     * @return string|false
89
     */
90
    protected function getCurrentPaymentMethod()
91
    {
92
        $oElement = $this->getDataByKey('element');
93
        if ($oElement) {
94
            $aOrigData = $oElement->getOriginalData();
95
            if (isset($aOrigData['path'])) {
96
                return str_replace('payone_payment/', '', $aOrigData['path']);
97
            }
98
        }
99
        return false;
100
    }
101
102
    /**
103
     * Returns Ratepay shop configurations for current payment method
104
     *
105
     * @return array
106
     */
107
    public function getRatepayShopConfig()
108
    {
109
        $sCurrentPaymentMethod = $this->getCurrentPaymentMethod();
110
111
        $aShopIds = $this->ratepayHelper->getRatepayShopConfigIdsByPaymentMethod($sCurrentPaymentMethod);
0 ignored issues
show
Bug introduced by
It seems like $sCurrentPaymentMethod can also be of type false; however, parameter $sPaymentMethod of Payone\Core\Helper\Ratep...figIdsByPaymentMethod() does only seem to accept string, 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

111
        $aShopIds = $this->ratepayHelper->getRatepayShopConfigIdsByPaymentMethod(/** @scrutinizer ignore-type */ $sCurrentPaymentMethod);
Loading history...
112
        if (empty($aShopIds)) {
113
            return [];
114
        }
115
        return $this->ratepayProfileResource->getProfileConfigsByIds($aShopIds);
116
    }
117
}
118