Test Setup Failed
Push — master ( 9fa851...19bcef )
by
unknown
15:59 queued 13:07
created

PaystackValidationException::hasErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Iamolayemi\Paystack\Exceptions;
4
5
use Exception;
6
7
/**
8
 * Exception thrown when input validation fails.
9
 */
10
class PaystackValidationException extends PaystackException
11
{
12
    /** @var array<string, string> */
13
    protected array $errors = [];
14
15
    /**
16
     * @param  array<string, string>  $errors
17
     */
18
    public function __construct(
19
        string $message = '',
20
        array $errors = [],
21
        int $code = 0,
22
        ?Exception $previous = null
23
    ) {
24
        parent::__construct($message, $code, $previous);
25
        $this->errors = $errors;
26
    }
27
28
    /**
29
     * @return array<string, string>
30
     */
31
    public function getErrors(): array
32
    {
33
        return $this->errors;
34
    }
35
36
    public function addError(string $field, string $message): self
37
    {
38
        $this->errors[$field] = $message;
39
40
        return $this;
41
    }
42
43
    public function hasErrors(): bool
44
    {
45
        return ! empty($this->errors);
46
    }
47
}
48