Completed
Push — master ( 778409...c54dd1 )
by Vincent
03:02
created

HasErrors   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 52
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setErrors() 0 5 1
A addError() 0 5 1
A fakeErrors() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VGirol\JsonApiFaker\Factory;
6
7
/**
8
 * Add "errors" member
9
 */
10
trait HasErrors
11
{
12
    /**
13
     * The "errors" member
14
     *
15
     * @var array<ErrorFactory>
16
     */
17
    public $errors;
18
19
    /**
20
     * Set the "errors" member
21
     *
22
     * @param array<ErrorFactory> $errors
23
     *
24
     * @return static
25
     */
26 4
    public function setErrors(array $errors)
27
    {
28 4
        $this->errors = $errors;
29
30 4
        return $this;
31
    }
32
33
    /**
34
     * Add a single error to the "errors" member
35
     *
36
     * @param ErrorFactory $error
37
     *
38
     * @return static
39
     */
40 1
    public function addError($error)
41
    {
42 1
        $this->addToArray('errors', $error);
0 ignored issues
show
Bug introduced by
It seems like addToArray() 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

42
        $this->/** @scrutinizer ignore-call */ 
43
               addToArray('errors', $error);
Loading history...
43
44 1
        return $this;
45
    }
46
47
    /**
48
     * Fill the "errors" member with fake values
49
     *
50
     * @param integer $count
51
     *
52
     * @return static
53
     */
54 1
    public function fakeErrors($count = 2)
55
    {
56 1
        $collection = [];
57 1
        for ($i = 0; $i < $count; $i++) {
58 1
            $collection[] = (new ErrorFactory)->fake();
59
        }
60
61 1
        return $this->setErrors($collection);
62
    }
63
}
64