Passed
Push — latest ( 5fe1f6...9a2102 )
by Mark
02:40
created

Normalize::shortcodes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.9666
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji\Util;
6
7
/**
8
 * {@internal}
9
 */
10
final class Normalize
11
{
12
    public const TYPES = ['array', 'bool', 'boolean', 'double', 'float', 'int', 'integer', 'null', 'object', 'string'];
13
14
    /**
15
     * @param mixed[]  $properties
16
     * @param string[] $types
17
     *
18
     * @return mixed[]
19
     */
20 54
    public static function properties(array $properties, array $types): array
21
    {
22 54
        $properties += \array_fill_keys(\array_keys($types), null);
23 54
        foreach ($properties as $key => $value) {
24 54
            $type             = $types[$key] ?? '?string';
25 54
            $properties[$key] = Property::cast($type, $value);
26
        }
27
28 54
        return $properties;
29
    }
30
31
    /**
32
     * @param string|string[] $shortcode
33
     *
34
     * @return string[]
35
     */
36 123
    public static function shortcodes($shortcode): array
37
    {
38 123
        $normalized = [];
39 123
        foreach (\func_get_args() as $shortcodes) {
40 123
            $normalized = \array_values(\array_unique(\array_merge(
41 123
                $normalized,
42 123
                \array_map(
43
                    static function ($shortcode) {
44 123
                        return \preg_replace('/[^a-z0-9-]/', '-', \strtolower(\trim($shortcode, ':(){}[]')));
45
                    },
46 123
                    (array) $shortcodes
47
                )
48
            )));
49
        }
50
51 123
        return \array_unique(\array_filter($normalized));
52
    }
53
}
54