Completed
Push — master ( 68a553...e9f254 )
by Milroy
01:21
created

Links::push()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sarala;
6
7
class Links
8
{
9
    private $links = [];
10
11
    public static function make()
12
    {
13
        return new self();
14
    }
15
16
    public function push(Link $link)
17
    {
18
        $this->links[$link->name()] = $link->data();
19
20
        return $this;
21
    }
22
23
    public function when($value, Link $link, Link $default = null)
24
    {
25
        if ($value) {
26
            $this->push($link);
27
        } elseif ($default) {
28
            $this->push($default);
29
        }
30
31
        return $this;
32
    }
33
34
    public function all(): array
35
    {
36
        return $this->links;
37
    }
38
}
39