SerializedOrJson::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 8
dl 0
loc 12
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\Model\Config\Backend;
28
29
use Magento\Framework\App\Config\Value;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Config\Value 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
class SerializedOrJson extends Value
32
{
33
    /**
34
     * PAYONE Base helper
35
     *
36
     * @var \Payone\Core\Helper\Base
37
     */
38
    protected $baseHelper;
39
40
    /**
41
     * @param \Magento\Framework\Model\Context                             $context
42
     * @param \Magento\Framework\Registry                                  $registry
43
     * @param \Magento\Framework\App\Config\ScopeConfigInterface           $config
44
     * @param \Magento\Framework\App\Cache\TypeListInterface               $cacheTypeList
45
     * @param \Payone\Core\Helper\Base                                     $baseHelper
46
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
47
     * @param \Magento\Framework\Data\Collection\AbstractDb|null           $resourceCollection
48
     * @param array                                                        $data
49
     */
50
    public function __construct(
51
        \Magento\Framework\Model\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Model\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...
52
        \Magento\Framework\Registry $registry,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Registry 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...
53
        \Magento\Framework\App\Config\ScopeConfigInterface $config,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Config\ScopeConfigInterface 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...
54
        \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Cache\TypeListInterface 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...
55
        \Payone\Core\Helper\Base $baseHelper,
56
        ?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Model\...eModel\AbstractResource 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...
57
        ?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Data\Collection\AbstractDb 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...
58
        array $data = []
59
    ) {
60
        parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
61
        $this->baseHelper = $baseHelper;
62
    }
63
64
    /**
65
     * @return void
66
     */
67
    protected function _afterLoad()
68
    {
69
        if (!is_array($this->getValue())) {
70
            $value = $this->getValue();
71
            $this->setValue(empty($value) ? false : $this->baseHelper->unserialize($value));
72
        }
73
    }
74
75
    /**
76
     * @return $this
77
     */
78
    public function beforeSave()
79
    {
80
        $value = $this->getValue();
81
        if (is_array($value)) {
82
            unset($value['__empty']);
83
            $value = $this->baseHelper->serialize($value);
84
        }
85
        $this->setValue($value);
86
        return parent::beforeSave();
87
    }
88
}