Link   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 7
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A link() 0 6 5
A __construct() 0 3 1
1
<?php
2
3
namespace kalanis\kw_routed_paths\Linking;
4
5
6
use kalanis\kw_paths\Interfaces\IPaths;
7
use kalanis\kw_paths\Stuff;
8
use kalanis\kw_routed_paths\Support;
9
10
11
/**
12
 * Class Link
13
 * @package kalanis\kw_routed_paths\Linking
14
 * The reverse side of class
15
 * @see \kalanis\kw_routed_paths\Sources\Request
16
 */
17
class Link
18
{
19
    protected string $prefix = '';
20
21 31
    public function __construct(string $prefix = '')
22
    {
23 31
        $this->prefix = $prefix;
24 31
    }
25
26
    /**
27
     * @param string[] $path
28
     * @param string[] $module
29
     * @param bool $moduleSingle
30
     * @param string|null $user
31
     * @return string
32
     */
33 31
    public function link(array $path, array $module = [], bool $moduleSingle = false, ?string $user = null): string
34
    {
35 31
        $prefix = !empty($this->prefix) ? Stuff::canonize($this->prefix) . IPaths::SPLITTER_SLASH : '';
36 31
        $modulePath = !empty($module) ? [Support::prefixWithSeparator($moduleSingle ? Support::PREFIX_MOD_SINGLE : Support::PREFIX_MOD_NORMAL) . Support::requestFromModuleName($module)] : [];
37 31
        $userPath = !empty($user) ? [Support::prefixWithSeparator(Support::PREFIX_USER) . $user] : [];
38 31
        return $prefix . strval(implode(IPaths::SPLITTER_SLASH, array_filter(array_merge($modulePath, $userPath, $path))));
39
    }
40
}
41