Passed
Pull Request — main (#24)
by Anatoly
04:51 queued 15s
created

InvalidDataException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 49
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getViolations() 0 17 2
A getExceptions() 0 3 1
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2021, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/hydrator/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/hydrator
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Hydrator\Exception;
15
16
use Symfony\Component\Validator\ConstraintViolation;
17
use Symfony\Component\Validator\ConstraintViolationList;
18
use Symfony\Component\Validator\ConstraintViolationListInterface;
19
use RuntimeException;
20
21
/**
22
 * InvalidDataException
23
 *
24
 * @since 3.0.0
25
 */
26
class InvalidDataException extends RuntimeException implements ExceptionInterface
27
{
28
29
    /**
30
     * @var list<InvalidValueException>
0 ignored issues
show
Bug introduced by
The type Sunrise\Hydrator\Exception\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
     */
32
    private array $exceptions;
33
34
    /**
35
     * Constructor of the class
36
     *
37
     * @param string $message
38
     * @param list<InvalidValueException> $exceptions
39
     */
40 116
    public function __construct(string $message, array $exceptions = [])
41
    {
42 116
        parent::__construct($message);
43
44 116
        $this->exceptions = $exceptions;
0 ignored issues
show
Documentation Bug introduced by
It seems like $exceptions of type array is incompatible with the declared type Sunrise\Hydrator\Exception\list of property $exceptions.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
    }
46
47
    /**
48
     * @return list<InvalidValueException>
49
     */
50 113
    final public function getExceptions(): array
51
    {
52 113
        return $this->exceptions;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->exceptions returns the type array which is incompatible with the documented return type Sunrise\Hydrator\Exception\list.
Loading history...
53
    }
54
55
    /**
56
     * @return ConstraintViolationListInterface
57
     */
58 1
    final public function getViolations(): ConstraintViolationListInterface
59
    {
60 1
        $violations = [];
61 1
        foreach ($this->exceptions as $exception) {
62 1
            $violations[] = new ConstraintViolation(
63 1
                $exception->getMessage(),
64 1
                null,
65 1
                [],
66 1
                null,
67 1
                $exception->getPropertyPath(),
68 1
                null,
69 1
                null,
70 1
                $exception->getErrorCode()
71 1
            );
72
        }
73
74 1
        return new ConstraintViolationList($violations);
75
    }
76
}
77