Completed
Push — master ( 2b565f...08a68e )
by Ma
02:52
created

ArrayHelper::fillWithDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
namespace Monitor\Utils;
3
4
class ArrayHelper
5
{
6
    
7
    /**
8
     * Fill array with concret value when can't find same key in $arrayTofill as in $struct array
9
     *
10
     * @param  array $struct
11
     * @param  array $arrayToFill
12
     * @param  int   $value
13
     * @return array $arrayMerged
14
     */
15 View Code Duplication
    public function fillWithDefaultValue(array $struct, array $arrayToFill, $value = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
    {
17
        $arrayDiff = array_diff($struct, $arrayToFill);
18
        $arrayDiffFilled = array_fill_keys($arrayDiff, $value);
19
        $arrayMerged = array_merge($arrayDiffFilled, $arrayToFill);
20
        return $arrayMerged;
21
    }
22
}