Passed
Push — master ( c38e78...642601 )
by Stephen
50s queued 12s
created

ArrayHelpers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 8
Bugs 1 Features 0
Metric Value
eloc 6
c 8
b 1
f 0
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 3 1
A sum() 0 9 3
1
<?php
2
3
namespace Sfneal\Helpers\Arrays;
4
5
use Sfneal\Helpers\Arrays\Utils\ArrayUtility;
6
7
class ArrayHelpers
8
{
9
    /**
10
     * Instantiate a `ArrayUtility` instance by passing an $array to the constructor.
11
     *
12
     * @param array $array
13
     * @return ArrayUtility
14
     */
15
    public static function from(array $array): ArrayUtility
16
    {
17
        return new ArrayUtility($array);
18
    }
19
20
    /**
21
     * Sum the values of two arrays.
22
     *
23
     * @param array $array1
24
     * @param array $array2
25
     * @return array
26
     */
27
    public static function sum(array $array1, array $array2): array
28
    {
29
        // todo: add ability to pass array of arrays
30
        $array = [];
31
        foreach ($array1 as $index => $value) {
32
            $array[$index] = isset($array2[$index]) ? $array2[$index] + $value : $value;
33
        }
34
35
        return $array;
36
    }
37
}
38