Passed
Push — develop ( 067c9c...bf1d25 )
by nguereza
04:45
created

Helper::arrayFlatten()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Platine Template
5
 *
6
 * Platine Template is a template engine that has taken a lot of inspiration from Django.
7
 *
8
 * This content is released under the MIT License (MIT)
9
 *
10
 * Copyright (c) 2020 Platine Template
11
 * Copyright (c) 2014 Guz Alexander, http://guzalexander.com
12
 * Copyright (c) 2011, 2012 Harald Hanek, http://www.delacap.com
13
 * Copyright (c) 2006 Mateo Murphy
14
 *
15
 * Permission is hereby granted, free of charge, to any person obtaining a copy
16
 * of this software and associated documentation files (the "Software"), to deal
17
 * in the Software without restriction, including without limitation the rights
18
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
 * copies of the Software, and to permit persons to whom the Software is
20
 * furnished to do so, subject to the following conditions:
21
 *
22
 * The above copyright notice and this permission notice shall be included in all
23
 * copies or substantial portions of the Software.
24
 *
25
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
 * SOFTWARE.
32
 */
33
34
/**
35
 *  @file Helper.php
36
 *
37
 *  The Helper class
38
 *
39
 *  @package    Platine\Template\Util
40
 *  @author Platine Developers Team
41
 *  @copyright  Copyright (c) 2020
42
 *  @license    http://opensource.org/licenses/MIT  MIT License
43
 *  @link   http://www.iacademy.cf
44
 *  @version 1.0.0
45
 *  @filesource
46
 */
47
48
declare(strict_types=1);
49
50
namespace Platine\Template\Util;
51
52
/**
53
 * Class Helper
54
 * @package Platine\Template\Util
55
 */
56
class Helper
57
{
58
59
    /**
60
     * Normalize path
61
     * @param string $path
62
     * @return string
63
     */
64
    public static function normalizePath(string $path): string
65
    {
66
        $normalizePath = rtrim($path, '/\\');
67
68
        return $normalizePath . DIRECTORY_SEPARATOR;
69
    }
70
71
    /**
72
     * Flatten a multidimensional array into a single array. Does not maintain keys.
73
     * @param array<mixed> $value
74
     * @return array<int, mixed>
75
     */
76
    public static function arrayFlatten(array $value): array
77
    {
78
        $result = [];
79
        foreach ($value as $element) {
80
            if (is_array($element)) {
81
                $result = array_merge($result, self::arrayFlatten($element));
82
            } else {
83
                $result[] = $element;
84
            }
85
        }
86
87
        return $result;
88
    }
89
90
    /**
91
     * Convert dashes to camel case
92
     * @param string $value
93
     * @return string
94
     */
95
    public static function dashesToCamelCase(string $value): string
96
    {
97
        $camelCase = str_replace('_', '', ucwords($value, '_'));
98
99
        return lcfirst($camelCase);
100
    }
101
}
102