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

HasErrors::fakeErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 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