AbstractValidationException::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 0
dl 0
loc 13
ccs 6
cts 6
cp 1
crap 3
rs 10
1
<?php
2
3
namespace MediaMonks\RestApi\Exception;
4
5
6
abstract class AbstractValidationException extends AbstractException implements ExceptionInterface, FieldExceptionInterface
7
{
8
    public function __construct(protected $message, protected $code)
9
    {
10
        parent::__construct($this->message, $this->code);
11
    }
12 5
13
    public function toArray(): array
14 5
    {
15 5
        $return = [
16 5
            'code'    => $this->getCode(),
17
            'message' => $this->getMessage(),
18
        ];
19
20
        /** @var ExceptionInterface|array $field */
21 3
        foreach ($this->getFields() as $field) {
22
            $return['fields'][] = is_array($field) ? $field : $field->toArray();
23
        }
24 3
25 3
        return $return;
26 3
    }
27
}
28