Completed
Pull Request — master (#13)
by
unknown
03:40
created

ConstraintViolations   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 42
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __toString() 0 14 2
A getViolations() 0 3 1
1
<?php
2
3
namespace ElevenLabs\Api\Service\Exception;
4
5
use ElevenLabs\Api\Validator\ConstraintViolation;
6
7
/**
8
 * Class ConstraintViolations.
9
 */
10
class ConstraintViolations extends ApiServiceError
11
{
12
    /**
13
     * @var array|ConstraintViolation[]
14
     */
15
    private $violations;
16
17
    /**
18
     * @param ConstraintViolation[] $violations
19
     */
20 7
    public function __construct(array $violations)
21
    {
22 7
        $this->violations = $violations;
23 7
        $this->message = $this->__toString();
24 7
        parent::__construct();
25 7
    }
26
27
    /**
28
     * @return array|ConstraintViolation[]
29
     */
30
    public function getViolations()
31
    {
32
        return $this->violations;
33
    }
34
35
    /**
36
     * @return string
37
     */
38 7
    public function __toString()
39
    {
40 7
        $message = "Request constraint violations:\n";
41 7
        foreach ($this->violations as $violation) {
42 4
            $message .= sprintf(
43 4
                "[property]: %s\n[message]: %s\n[constraint]: %s\n[location]: %s\n\n",
44 4
                $violation->getProperty(),
45 4
                $violation->getMessage(),
46 4
                $violation->getConstraint(),
47 4
                $violation->getLocation()
48
            );
49
        }
50
51 7
        return $message;
52
    }
53
}
54