Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 6f78dc...d7c2e2 )
by Jérémiah
21s queued 11s
created

UserErrors::setErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
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 Overblog\GraphQLBundle\Error;
6
7
use Exception;
8
use InvalidArgumentException;
9
use RuntimeException;
10
use function is_object;
11
use function is_string;
12
use function sprintf;
13
14
class UserErrors extends RuntimeException
15
{
16
    /** @var UserError[] */
17
    private array $errors = [];
18
19 2
    public function __construct(
20
        array $errors,
21
        string $message = '',
22
        int $code = 0,
23
        Exception $previous = null
24
    ) {
25 2
        $this->setErrors($errors);
26 1
        parent::__construct($message, $code, $previous);
27 1
    }
28
29
    /**
30
     * @param UserError[]|string[] $errors
31
     */
32 2
    public function setErrors(array $errors): void
33
    {
34 2
        foreach ($errors as $error) {
35 2
            $this->addError($error);
36
        }
37 1
    }
38
39
    /**
40
     * @param string|\GraphQL\Error\UserError $error
41
     */
42 2
    public function addError($error): self
43
    {
44 2
        if (is_string($error)) {
45 2
            $error = new UserError($error);
46 2
        } elseif (!is_object($error) || !$error instanceof \GraphQL\Error\UserError) {
47 1
            throw new InvalidArgumentException(sprintf('Error must be string or instance of %s.', \GraphQL\Error\UserError::class));
48
        }
49
50 2
        $this->errors[] = $error;
51
52 2
        return $this;
53
    }
54
55
    /**
56
     * @return UserError[]
57
     */
58 1
    public function getErrors(): array
59
    {
60 1
        return $this->errors;
61
    }
62
}
63