ValidatorException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 49
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setError() 0 3 1
A setErrors() 0 3 1
A getErrors() 0 3 1
A hasErrors() 0 3 1
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Validator\Exception;
13
14
use Bluz\Http\Exception\BadRequestException;
15
16
/**
17
 * Validator Exception
18
 *
19
 * @package  Bluz\Validator\Exception
20
 * @author   Anton Shevchuk
21
 */
22
class ValidatorException extends BadRequestException
23
{
24
    /**
25
     * @var string exception message
26
     */
27
    protected $message = 'Invalid Arguments';
28
29
    /**
30
     * @var array of error's messages
31
     */
32
    protected $errors = [];
33
34
    /**
35
     * @return array
36
     */
37 3
    public function getErrors(): array
38
    {
39 3
        return $this->errors;
40
    }
41
42
    /**
43
     * @param array $errors
44
     */
45
    public function setErrors(array $errors): void
46
    {
47
        $this->errors = $errors;
48
    }
49
50
    /**
51
     * Add Error by field name
52
     *
53
     * @param string $name
54
     * @param string $message
55
     *
56
     * @return void
57
     */
58 4
    public function setError(string $name, string $message): void
59
    {
60 4
        $this->errors[$name] = $message;
61 4
    }
62
63
    /**
64
     * Has errors?
65
     *
66
     * @return bool
67
     */
68 6
    public function hasErrors(): bool
69
    {
70 6
        return (bool) count($this->errors);
71
    }
72
}
73