Completed
Push — master ( 4568b1...9a246b )
by Anton
05:03
created

ValidatorException::hasErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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