KeyNormalizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A array_map_keys() 0 9 2
A normalize() 0 8 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sjhc1170
5
 * Date: 07/05/2018
6
 * Time: 10:34
7
 */
8
9
namespace Iriven\Plugins\Form\Core\Libs\Traits;
10
11
12
trait KeyNormalizer
13
{
14
    /**
15
     * @param $keys
16
     * @return bool|mixed|string
17
     */
18
    private function normalize($keys)
19
    {
20
        if(is_array($keys)) return false;
21
        foreach (array(' ', '&nbsp;', '\n', '\t', '\r', '"','\'','_') as $strip)
22
            $keys = str_replace($strip, '', (string) $keys);
23
        $keys = trim(preg_replace('/\W+/', '-', $keys), '-');
24
        $keys = strtolower(str_ireplace('input','',$keys));
0 ignored issues
show
Bug introduced by
It seems like str_ireplace('input', '', $keys) can also be of type array; however, parameter $string of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

24
        $keys = strtolower(/** @scrutinizer ignore-type */ str_ireplace('input','',$keys));
Loading history...
25
        return $keys;
26
    }
27
28
    /**
29
     * @param callable $callable
30
     * @param array    $array
31
     * @return array
32
     */
33
    private function array_map_keys (callable $callable, array $array) : array
34
    {
35
        $map = [];
36
        foreach ($array as $key => $value)
37
        {
38
            $key = call_user_func($callable,$key);
39
            $map[$key] = $value;
40
        }
41
        return $map;
42
    }
43
44
}