Passed
Push — master ( 7349d0...85c6cc )
by Nikolaos
04:18
created

EvolvableLinkProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 44
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withoutLink() 0 8 1
A withLink() 0 8 1
1
<?php
2
3
/**
4
 * This file is part of the Phalcon Framework.
5
 *
6
 * For the full copyright and license information, please view the LICENSE.md
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Phalcon\Html\Link;
13
14
use Psr\Link\EvolvableLinkProviderInterface;
15
use Psr\Link\LinkInterface;
16
17
/**
18
 * Class LinkProvider
19
 *
20
 * @package Phalcon\Link
21
 *
22
 * @property LinkInterface[] $links
23
 */
24
class EvolvableLinkProvider extends LinkProvider implements EvolvableLinkProviderInterface
25
{
26
    /**
27
     * Returns an instance with the specified link included.
28
     *
29
     * If the specified link is already present, this method MUST return
30
     * normally without errors. The link is present if $link is === identical
31
     * to a link object already in the collection.
32
     *
33
     * @param LinkInterface $link
34
     *   A link object that should be included in this collection.
35
     *
36
     * @return static
37
     */
38 1
    public function withLink(LinkInterface $link)
39
    {
40 1
        $key         = $this->getKey($link);
41 1
        $newInstance = clone $this;
42
43 1
        $newInstance->links[$key] = $link;
44
45 1
        return $newInstance;
46
    }
47
48
    /**
49
     * Returns an instance with the specified link removed.
50
     *
51
     * If the specified link is not present, this method MUST return normally
52
     * without errors. The link is present if $link is === identical to a link
53
     * object already in the collection.
54
     *
55
     * @param LinkInterface $link
56
     *   The link to remove.
57
     *
58
     * @return static
59
     */
60 1
    public function withoutLink(LinkInterface $link)
61
    {
62 1
        $key         = $this->getKey($link);
63 1
        $newInstance = clone $this;
64
65 1
        unset($newInstance->links[$key]);
66
67 1
        return $newInstance;
68
    }
69
}
70