1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | namespace VGirol\JsonApiFaker\Factory; |
||||||
6 | |||||||
7 | use VGirol\JsonApiConstant\Members; |
||||||
8 | |||||||
9 | /** |
||||||
10 | * Add "meta" member to a factory. |
||||||
11 | */ |
||||||
12 | trait HasMeta |
||||||
13 | { |
||||||
14 | /** |
||||||
15 | * The "meta" member |
||||||
16 | * |
||||||
17 | * @var array |
||||||
18 | */ |
||||||
19 | protected $meta; |
||||||
20 | |||||||
21 | /** |
||||||
22 | * Set the "meta" member. |
||||||
23 | * |
||||||
24 | * @param array $meta |
||||||
25 | * |
||||||
26 | * @return static |
||||||
27 | */ |
||||||
28 | 84 | public function setMeta(array $meta) |
|||||
29 | { |
||||||
30 | 84 | $this->meta = $meta; |
|||||
31 | |||||||
32 | 84 | return $this; |
|||||
33 | } |
||||||
34 | |||||||
35 | /** |
||||||
36 | * Get the "meta" member. |
||||||
37 | * |
||||||
38 | * @return array|null |
||||||
39 | */ |
||||||
40 | 33 | public function getMeta(): ?array |
|||||
41 | { |
||||||
42 | 33 | return $this->meta; |
|||||
43 | } |
||||||
44 | |||||||
45 | /** |
||||||
46 | * Add a single value to the "meta" member |
||||||
47 | * |
||||||
48 | * @param string $name |
||||||
49 | * @param mixed $value |
||||||
50 | * |
||||||
51 | * @return static |
||||||
52 | */ |
||||||
53 | 15 | public function addToMeta(string $name, $value) |
|||||
54 | { |
||||||
55 | 15 | $this->addToObject(Members::META, $name, $value); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
56 | |||||||
57 | 15 | return $this; |
|||||
58 | } |
||||||
59 | |||||||
60 | /** |
||||||
61 | * Fill the "meta" member with fake values. |
||||||
62 | * |
||||||
63 | * @param integer $count The number of values to generate. |
||||||
64 | * |
||||||
65 | * @return static |
||||||
66 | */ |
||||||
67 | 60 | public function fakeMeta(int $count = 5) |
|||||
68 | { |
||||||
69 | 60 | $this->setMeta( |
|||||
70 | 60 | $this->fakeMembers($count) |
|||||
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
![]() |
|||||||
71 | ); |
||||||
72 | |||||||
73 | 60 | return $this; |
|||||
74 | } |
||||||
75 | } |
||||||
76 |