Passed
Push — master ( c227df...528f97 )
by Petr
07:58
created

Link   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
    /** @var string */
20
    protected $prefix = '';
21
22 31
    public function __construct(string $prefix = '')
23
    {
24 31
        $this->prefix = $prefix;
25 31
    }
26
27
    /**
28
     * @param string[] $path
29
     * @param string[] $module
30
     * @param bool $moduleSingle
31
     * @param string|null $user
32
     * @return string
33
     */
34 31
    public function link(array $path, array $module = [], bool $moduleSingle = false, ?string $user = null): string
35
    {
36 31
        $prefix = !empty($this->prefix) ? Stuff::canonize($this->prefix) . IPaths::SPLITTER_SLASH : '';
37 31
        $modulePath = !empty($module) ? [Support::prefixWithSeparator($moduleSingle ? Support::PREFIX_MOD_SINGLE : Support::PREFIX_MOD_NORMAL) . Support::requestFromModuleName($module)] : [];
38 31
        $userPath = !empty($user) ? [Support::prefixWithSeparator(Support::PREFIX_USER) . $user] : [];
39 31
        return $prefix . strval(implode(IPaths::SPLITTER_SLASH, array_filter(array_merge($modulePath, $userPath, $path))));
40
    }
41
}
42