ValidatorException::hasErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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