Util   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A slug() 0 6 1
A path() 0 5 1
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