Completed
Push — master ( da0ab4...8ffee5 )
by Vincent
03:47
created

HasLinks::getLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
/**
8
 * Add "links" member to a factory.
9
 */
10
trait HasLinks
11
{
12
    /**
13
     * The "links" member
14
     *
15
     * @var array
16
     */
17
    protected $links;
18
19
    /**
20
     * Set the "links" member.
21
     *
22
     * @param array $links
23
     *
24
     * @return static
25
     */
26 57
    public function setLinks(array $links)
27
    {
28 57
        $this->links = $links;
29
30 57
        return $this;
31
    }
32
33
    /**
34
     * Set the "links" member.
35
     *
36
     * @return array|null
37
     */
38 27
    public function getLinks(): ?array
39
    {
40 27
        return $this->links;
41
    }
42
43
    /**
44
     * Add some links to the "links" member.
45
     *
46
     * @param array $links
47
     *
48
     * @return static
49
     */
50 3
    public function addLinks(array $links)
51
    {
52 3
        foreach ($links as $name => $link) {
53 3
            $this->addLink($name, $link);
54
        }
55
56 3
        return $this;
57
    }
58
59
    /**
60
     * Add a single link to the "links" member
61
     *
62
     * @param string $name
63
     * @param array|string|null $link
64
     *
65
     * @return static
66
     */
67 6
    public function addLink(string $name, $link)
68
    {
69 6
        $this->addToObject('links', $name, $link);
0 ignored issues
show
Bug introduced by
It seems like addToObject() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        $this->/** @scrutinizer ignore-call */ 
70
               addToObject('links', $name, $link);
Loading history...
70
71 6
        return $this;
72
    }
73
74
    /**
75
     * Fill the "links" member with fake values.
76
     *
77
     * @param array $links
78
     *
79
     * @return static
80
     */
81 39
    public function fakeLinks($links = ['self' => ['url']])
82
    {
83 39
        $this->setLinks(
84 39
            $this->fakeMembers($links)
0 ignored issues
show
Bug introduced by
It seems like fakeMembers() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
            $this->/** @scrutinizer ignore-call */ 
85
                   fakeMembers($links)
Loading history...
85
        );
86
87 39
        return $this;
88
    }
89
}
90