Util::path()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Helix\Site;
4
5
/**
6
 * Static helper functions.
7
 */
8
class Util
9
{
10
11
    /**
12
     * Joins string pieces and formats it as an absolute path.
13
     *
14
     * @param string ...$args
15
     * @return string
16
     */
17
    public static function path(string ...$args): string
18
    {
19
        $path = trim(implode('/', $args), '/');
20
        $path = preg_replace('/\/+/', '/', $path);
21
        return '/' . $path;
22
    }
23
24
    /**
25
     * Joins string pieces and formats it as a human friendly slug.
26
     *
27
     * @param string ...$args
28
     * @return string
29
     */
30
    public static function slug(string ...$args): string
31
    {
32
        $slug = strtolower(implode('-', $args));
33
        $slug = preg_replace('/([^a-z0-9]+)/', '-', $slug);
34
        $slug = preg_replace('/-+/', '-', $slug);
35
        return trim($slug, '-');
36
    }
37
}
38