Completed
Push — master ( 96f4b7...08b9b2 )
by Mr
02:16
created

Helper::denormalizeClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ComposerJson;
4
5
trait Helper
6
{
7
    /**
8
     * Normalize parameter from camelCase to composer-case
9
     *
10
     * @param string $name
11
     *
12
     * @return string
13
     */
14
    private function normalize(string $name): string
15
    {
16
        return strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '-$0', $name), '-'));
17
    }
18
19
    /**
20
     * Convert string like "require-dev" to "requireDev"
21
     *
22
     * @param string $name
23
     *
24
     * @return string
25
     */
26
    private function denormalize(string $name): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
27
    {
28
        $exploded = array_map(function ($item) {
29
            return ucfirst($item);
30
        }, explode('-', $name));
31
32
        return lcfirst(implode('', $exploded));
33
    }
34
35
    /**
36
     * Convert string like "require-dev" to "requireDev"
37
     *
38
     * @param string $name
39
     *
40
     * @return string
41
     */
42
    private function denormalizeClassName(string $name): string
43
    {
44
        $class = explode('\\', $name);
45
        $class = $class[array_key_last($class)];
46
47
        return $this->normalize($class);
48
    }
49
50
    /**
51
     * Convert string to normal name
52
     *
53
     * @param string $name
54
     *
55
     * @return string
56
     */
57
    private function normalizeMethodName(string $name): string
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
58
    {
59
        return str_replace(' ', '', ucwords(implode(' ', explode('-', $name))));
60
    }
61
}
62