Passed
Push — develop ( f1431d...068811 )
by Andrew
05:25 queued 18s
created

ArrayHelper::strictMerge()   C

Complexity

Conditions 11
Paths 16

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 20
nc 16
nop 2
dl 0
loc 35
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS 3.x
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2017 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\helpers;
13
14
use yii\helpers\ReplaceArrayValue;
15
use yii\helpers\UnsetArrayValue;
16
17
/**
18
 * @author    nystudio107
19
 * @package   Seomatic
20
 * @since     3.0.0
21
 */
22
class ArrayHelper extends \craft\helpers\ArrayHelper
23
{
24
    // Public Static Methods
25
    // =========================================================================
26
27
    /**
28
     * @param array    $array
29
     * @param callable $callback
30
     *
31
     * @return array
32
     */
33
    public static function arrayFilterRecursive(array $array, callable $callback)
34
    {
35
        foreach ($array as $k => $v) {
36
            if (is_array($v)) {
37
                $array[$k] = self::arrayFilterRecursive($v, $callback);
38
            } else {
39
                if ($callback($v, $k)) {
40
                    unset($array[$k]);
41
                }
42
            }
43
        }
44
45
        return $array;
46
    }
47
48
    /**
49
     * @param $value
50
     * @param $key
51
     *
52
     * @return bool
53
     */
54
    public static function unsetEmptyChildren($value, $key)
1 ignored issue
show
Unused Code introduced by
The parameter $key 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

54
    public static function unsetEmptyChildren($value, /** @scrutinizer ignore-unused */ $key)

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...
55
    {
56
        if (is_bool($value)) {
57
            return false;
58
        } else {
59
            return empty($value) ? true : false;
60
        }
61
    }
62
63
    /**
64
     * @param $value
65
     * @param $key
66
     *
67
     * @return bool
68
     */
69
    public static function unsetNullChildren($value, $key)
1 ignored issue
show
Unused Code introduced by
The parameter $key 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

69
    public static function unsetNullChildren($value, /** @scrutinizer ignore-unused */ $key)

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...
70
    {
71
        return $value == null ? true : false;
72
    }
73
}
74