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

Url::href()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
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
}