TestUtils::arrayChangeKeyCaseDeep()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 8
rs 10
1
<?php
2
3
namespace Signify\Tests;
4
5
use SilverStripe\Core\Config\Config;
6
7
abstract class TestUtils
8
{
9
10
    /**
11
     * Perform a test with some specific configuration which should not affect other tests.
12
     *
13
     * @param array $configMap
14
     * @param Callable $testCallback
15
     */
16
    public static function testWithConfig($configMap, $testCallback)
17
    {
18
        $originalConfigValues = array();
19
        // Set new config values.
20
        foreach ($configMap as $class => $config) {
21
            foreach ($config as $key => $value) {
22
                $originalConfigValues[$class][$key] = Config::inst()->get($class, $key);
23
                Config::inst()->update($class, $key, $value);
0 ignored issues
show
Bug introduced by
The method update() does not exist on SilverStripe\Config\Coll...nfigCollectionInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
                Config::inst()->/** @scrutinizer ignore-call */ update($class, $key, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
            }
25
        }
26
27
        // Perform test with specific configuration.
28
        $testCallback();
29
30
        // Restore original config values.
31
        foreach ($originalConfigValues as $class => $config) {
32
            foreach ($config as $key => $value) {
33
                Config::inst()->update($class, $key, $value);
34
            }
35
        }
36
    }
37
38
    public static function arrayChangeKeyCaseDeep(array $input, $case = null)
39
    {
40
        foreach ($input as $header => &$value) {
41
            if (is_array($value)) {
42
                $value = self::arrayChangeKeyCaseDeep($value, $case);
43
            }
44
        }
45
        return array_change_key_case($input, $case);
46
    }
47
}
48