AbstractMapper::removeRedundantParams()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
cc 5
eloc 8
c 3
b 2
f 0
nc 3
nop 1
dl 0
loc 16
rs 9.6111
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\AdyenApi\Business\Mapper;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\AdyenApiRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AdyenApiRequestTransfer 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...
12
use SprykerEco\Zed\AdyenApi\AdyenApiConfig;
13
14
abstract class AbstractMapper
15
{
16
    /**
17
     * @var \SprykerEco\Zed\AdyenApi\AdyenApiConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @param \Generated\Shared\Transfer\AdyenApiRequestTransfer $adyenApiRequestTransfer
23
     *
24
     * @return void
25
     */
26
    abstract protected function validateRequestTransfer(AdyenApiRequestTransfer $adyenApiRequestTransfer): void;
27
28
    /**
29
     * @param \SprykerEco\Zed\AdyenApi\AdyenApiConfig $config
30
     */
31
    public function __construct(AdyenApiConfig $config)
32
    {
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * @param array $data
38
     *
39
     * @return array
40
     */
41
    protected function removeRedundantParams(array $data): array
42
    {
43
        $data = array_filter($data, function ($item) {
44
            if ($item instanceof ArrayObject) {
45
                return $item->count() !== 0;
46
            }
47
            return !empty($item);
48
        });
49
50
        foreach ($data as $key => $value) {
51
            if (is_array($value) || $value instanceof ArrayObject) {
52
                $data[$key] = $this->removeRedundantParams($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type ArrayObject; however, parameter $data of SprykerEco\Zed\AdyenApi\...removeRedundantParams() does only seem to accept array, 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

52
                $data[$key] = $this->removeRedundantParams(/** @scrutinizer ignore-type */ $value);
Loading history...
53
            }
54
        }
55
56
        return $data;
57
    }
58
}
59