Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ValidationError
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 merge
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 field
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 code
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 details
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Shared\Domain\Validation;
4
5use App\Shared\Domain\Exception\BaseErrorCode;
6use App\Shared\Domain\Exception\ErrorCode;
7
8/**
9 * A validation error on a field, with a specific ErrorCode and details as an array
10 * @see ErrorCode
11 *
12 * @author Wilhelm Zwertvaegher
13 */
14class ValidationError
15{
16
17    /**
18     * @param String $field
19     * @param BaseErrorCode $code
20     * @param array<string, string|int> $details as a detailKey => message|number array
21     */
22    public function __construct(private readonly String $field, private readonly BaseErrorCode $code, private array $details = [])
23    {
24    }
25
26
27    public function merge(ValidationError $error): void
28    {
29        if (count($error->details)) {
30            $this->details = array_merge($this->details, $error->details);
31        }
32    }
33
34    public function field(): string
35    {
36        return $this->field;
37    }
38
39    public function code(): BaseErrorCode
40    {
41        return $this->code;
42    }
43
44    /**
45     * @return array<string, string|int>
46     */
47    public function details(): array
48    {
49        return $this->details;
50    }
51
52    public function __toString(): string
53    {
54        return sprintf(
55            "ValidationError[code = %s, message = %s {field = %s, details = %s]",
56            $this->code->getCode(),
57            $this->code->getMessage(),
58            $this->field,
59            json_encode($this->details)
60        );
61    }
62}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

ValidationError->__construct
22    public function __construct(private readonly String $field, private readonly BaseErrorCode $code, private array $details = [])
23    {
24    }
ValidationError->__toString
54        return sprintf(
55            "ValidationError[code = %s, message = %s {field = %s, details = %s]",
56            $this->code->getCode(),
57            $this->code->getMessage(),
58            $this->field,
59            json_encode($this->details)
60        );
61    }
ValidationError->code
41        return $this->code;
42    }
ValidationError->details
49        return $this->details;
50    }
ValidationError->field
36        return $this->field;
37    }
ValidationError->merge
27    public function merge(ValidationError $error): void
28    {
29        if (count($error->details)) {
30            $this->details = array_merge($this->details, $error->details);
31        }
32    }
32    }
{main}
3namespace App\Shared\Domain\Validation;
4
5use App\Shared\Domain\Exception\BaseErrorCode;
6use App\Shared\Domain\Exception\ErrorCode;
7
8/**
9 * A validation error on a field, with a specific ErrorCode and details as an array
10 * @see ErrorCode
11 *
12 * @author Wilhelm Zwertvaegher
13 */
14class ValidationError
15{
16
17    /**
18     * @param String $field
19     * @param BaseErrorCode $code
20     * @param array<string, string|int> $details as a detailKey => message|number array
21     */
22    public function __construct(private readonly String $field, private readonly BaseErrorCode $code, private array $details = [])
23    {
24    }
25
26
27    public function merge(ValidationError $error): void
28    {
29        if (count($error->details)) {
30            $this->details = array_merge($this->details, $error->details);
31        }
32    }
33
34    public function field(): string
35    {
36        return $this->field;
37    }
38
39    public function code(): BaseErrorCode
40    {
41        return $this->code;
42    }
43
44    /**
45     * @return array<string, string|int>
46     */
47    public function details(): array
48    {
49        return $this->details;
50    }
51
52    public function __toString(): string
53    {
54        return sprintf(
55            "ValidationError[code = %s, message = %s {field = %s, details = %s]",
56            $this->code->getCode(),
57            $this->code->getMessage(),
58            $this->field,
59            json_encode($this->details)
60        );
61    }