1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | namespace VGirol\JsonApiFaker\Factory; |
||||||
6 | |||||||
7 | use VGirol\JsonApiConstant\Members; |
||||||
8 | |||||||
9 | /** |
||||||
10 | * Add "links" member to a factory. |
||||||
11 | */ |
||||||
12 | trait HasLinks |
||||||
13 | { |
||||||
14 | /** |
||||||
15 | * The "links" member |
||||||
16 | * |
||||||
17 | * @var array |
||||||
18 | */ |
||||||
19 | protected $links; |
||||||
20 | |||||||
21 | /** |
||||||
22 | * Set the "links" member. |
||||||
23 | * |
||||||
24 | * @param array $links |
||||||
25 | * |
||||||
26 | * @return static |
||||||
27 | */ |
||||||
28 | 57 | public function setLinks(array $links) |
|||||
29 | { |
||||||
30 | 57 | $this->links = $links; |
|||||
31 | |||||||
32 | 57 | return $this; |
|||||
33 | } |
||||||
34 | |||||||
35 | /** |
||||||
36 | * Set the "links" member. |
||||||
37 | * |
||||||
38 | * @return array|null |
||||||
39 | */ |
||||||
40 | 27 | public function getLinks(): ?array |
|||||
41 | { |
||||||
42 | 27 | return $this->links; |
|||||
43 | } |
||||||
44 | |||||||
45 | /** |
||||||
46 | * Add some links to the "links" member. |
||||||
47 | * |
||||||
48 | * @param array $links |
||||||
49 | * |
||||||
50 | * @return static |
||||||
51 | */ |
||||||
52 | 3 | public function addLinks(array $links) |
|||||
53 | { |
||||||
54 | 3 | foreach ($links as $name => $link) { |
|||||
55 | 3 | $this->addLink($name, $link); |
|||||
56 | } |
||||||
57 | |||||||
58 | 3 | return $this; |
|||||
59 | } |
||||||
60 | |||||||
61 | /** |
||||||
62 | * Add a single link to the "links" member |
||||||
63 | * |
||||||
64 | * @param string $name |
||||||
65 | * @param array|string|null $link |
||||||
66 | * |
||||||
67 | * @return static |
||||||
68 | */ |
||||||
69 | 6 | public function addLink(string $name, $link) |
|||||
70 | { |
||||||
71 | 6 | $this->addToObject(Members::LINKS, $name, $link); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
72 | |||||||
73 | 6 | return $this; |
|||||
74 | } |
||||||
75 | |||||||
76 | /** |
||||||
77 | * Fill the "links" member with fake values. |
||||||
78 | * |
||||||
79 | * @param array $links |
||||||
80 | * |
||||||
81 | * @return static |
||||||
82 | */ |
||||||
83 | 39 | public function fakeLinks($links = [Members::LINK_SELF => ['url']]) |
|||||
84 | { |
||||||
85 | 39 | $this->setLinks( |
|||||
86 | 39 | $this->fakeMembers($links) |
|||||
0 ignored issues
–
show
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
![]() |
|||||||
87 | ); |
||||||
88 | |||||||
89 | 39 | return $this; |
|||||
90 | } |
||||||
91 | } |
||||||
92 |