Passed
Push — master ( e985ab...f5765f )
by Mihail
04:35
created

Url   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A href() 0 8 3
A buildLinkString() 0 3 1
A __construct() 0 11 1
1
<?php
2
3
namespace Helper\Url;
4
5
6
use Ffcms\Core\Helper\Type\Str;
7
8
9
/**
10
 * Class Url. Build and parse urls
11
 * @package Helper\Url
12
 */
13
class Url
14
{
15
    private $controller;
16
    private $action;
17
    private $id;
18
    private $add;
19
    private $query;
20
    private $encode = false;
21
22
    /**
23
     * Url constructor. Create instance before process params
24
     * @param string $controllerAction
25
     * @param null|string $id
26
     * @param null|string $add
27
     * @param array|null $query
28
     * @param bool $encode
29
     */
30
    public function __construct(string $controllerAction, ?string $id, ?string $add, ?array $query = null, bool $encode = false)
31
    {
32
        $controllerAction = Str::lowerCase(trim($controllerAction, '/'));
33
        [$controller, $action] = explode('/', $controllerAction);
34
35
        $this->controller = $controller;
36
        $this->action = $action;
37
        $this->id = $id;
38
        $this->add = $add;
39
        $this->query = $query;
40
        $this->encode = $encode;
41
    }
42
43
    /**
44
     * Build link from passed params. Old method Url::to() -> Url::href
45
     * @param array|null $to
46
     * @param bool $encode
47
     * @return null|string
48
     */
49
    public static function href(?array $to = null, bool $encode = false): ?string
50
    {
51
        if (!$to || !isset($to[0])) {
52
            return null;
53
        }
54
55
        $instance = new self($to[0], $to[1], $to[2], $to[3], $encode);
56
        return $instance->buildLinkString();
57
    }
58
59
    private function buildLinkString()
60
    {
61
        return 'test';
62
    }
63
}