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

HasRelationships   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRelationship() 0 5 1
A fakeRelationships() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
trait HasRelationships
8
{
9
    /**
10
     * Undocumented variable
11
     *
12
     * @var array<string, RelationshipFactory>
13
     */
14
    public $relationships;
15
16
    /**
17
     * Undocumented function
18
     *
19
     * @param string $name
20
     * @param RelationshipFactory $relationship
21
     *
22
     * @return static
23
     */
24 8
    public function addRelationship(string $name, $relationship)
25
    {
26 8
        $this->addToObject('relationships', $name, $relationship);
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

26
        $this->/** @scrutinizer ignore-call */ 
27
               addToObject('relationships', $name, $relationship);
Loading history...
27
28 8
        return $this;
29
    }
30
31
    /**
32
     * Undocumented function
33
     *
34
     * @param integer $count
35
     *
36
     * @return static
37
     */
38 5
    public function fakeRelationships($count = 2)
39
    {
40 5
        $faker = \Faker\Factory::create();
41
42 5
        for ($i = 0; $i < $count; $i++) {
43 5
            $this->addRelationship(
44 5
                $faker->unique()->numerify('relationship##'),
45 5
                (new RelationshipFactory)->fake()
46
            );
47
        }
48
49 5
        return $this;
50
    }
51
}
52