Passed
Push — develop ( 3d469b...25fedc )
by Andrew
02:34
created

ArrayUtil::searchAndReplace()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 1
nop 3
crap 2
1
<?php
2
3
4
namespace ddlzz\AmoAPI\Utils;
5
6
7
/**
8
 * Class ArrayUtil
9
 * @package ddlzz\AmoAPI\Utils
10
 * @author ddlzz
11
 */
12
class ArrayUtil
13
{
14
    /**
15
     * Replaces a value in a multidimensional array with another value
16
     * @param int|string $search
17
     * @param int|string $replace
18
     * @param array $haystack
19
     * @return array
20
     */
21
    public static function searchAndReplace($search, $replace, $haystack)
22
    {
23 2
        $callback = function(&$value, $key, array $params) {
24 2
            if (($params['search'] === $value)) {
25 2
                $value = $params['replace'];
26
            }
27 2
        };
28
29 2
        array_walk_recursive($haystack, $callback, ['search' => $search, 'replace' => $replace]);
30
31 2
        return $haystack;
32
    }
33
}