Completed
Push — master ( 883f28...097345 )
by Vincent
03:45 queued 11s
created

HasLinks   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 60
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addLinks() 0 7 2
A setLinks() 0 5 1
A addLink() 0 5 1
A fakeLinks() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
trait HasLinks
8
{
9
    public $links;
10
11
    /**
12
     * Undocumented function
13
     *
14
     * @param array $links
15
     * @return static
16
     */
17 12
    public function setLinks(array $links)
18
    {
19 12
        $this->links = $links;
20
21 12
        return $this;
22
    }
23
24
    /**
25
     * Undocumented function
26
     *
27
     * @param array $links
28
     * @return static
29
     */
30 1
    public function addLinks(array $links)
31
    {
32 1
        foreach ($links as $name => $link) {
33 1
            $this->addLink($name, $link);
34
        }
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * Undocumented function
41
     *
42
     * @param string $name
43
     * @param array|string|null $link
44
     * @return static
45
     */
46 2
    public function addLink(string $name, $link)
47
    {
48 2
        $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

48
        $this->/** @scrutinizer ignore-call */ 
49
               addToObject('links', $name, $link);
Loading history...
49
50 2
        return $this;
51
    }
52
53
    /**
54
     * Undocumented function
55
     *
56
     * @param array $keys
57
     *
58
     * @return static
59
     */
60 7
    public function fakeLinks($links = ['self' => ['url']])
61
    {
62 7
        $this->setLinks(
63 7
            $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

63
            $this->/** @scrutinizer ignore-call */ 
64
                   fakeMembers($links)
Loading history...
64
        );
65
66 7
        return $this;
67
    }
68
}
69