MultipleError   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A addError() 0 4 1
A getHttpStatusCode() 0 4 1
A getPayload() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\JsonApiResponseFactory\Model;
6
7
use Happyr\JsonApiResponseFactory\ResponseModelInterface;
8
9
/**
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
final class MultipleError implements ResponseModelInterface
13
{
14
    private $httpStatusCode;
15
16
    /**
17
     * @var AbstractError[]
18
     */
19
    private $errors;
20
21 3
    public function __construct(int $httpStatusCode, array $errors)
22
    {
23 3
        $this->httpStatusCode = $httpStatusCode;
24 3
        foreach ($errors as $error) {
25 1
            $this->addError($error);
26
        }
27 3
    }
28
29 2
    public function addError(AbstractError $error): void
30
    {
31 2
        $this->errors[] = $error;
32 2
    }
33
34 1
    public function getHttpStatusCode(): int
35
    {
36 1
        return $this->httpStatusCode;
37
    }
38
39 1
    public function getPayload(): array
40
    {
41 1
        $data = [];
42 1
        foreach ($this->errors as $error) {
43 1
            $data[] = $error->getErrorData();
44
        }
45
46
        return [
47 1
            'errors' => $data,
48
        ];
49
    }
50
}
51