Passed
Pull Request — master (#16)
by Dedipyaman
01:35
created

Result::getErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Phypes\Result;
4
5
use Phypes\Error\Error;
6
7
abstract class Result
8
{
9
    private $valid;
10
    private $errors = [];
11
12
    public function __construct(bool $valid, Error... $errors)
13
    {
14
        $this->valid = $valid;
15
        $this->errors = $errors;
16
    }
17
18
    public function isValid() : bool
19
    {
20
        return $this->valid;
21
    }
22
23
    /**
24
     * @return array
25
     */
26
    public function getErrors(): array
27
    {
28
        return $this->errors;
29
    }
30
31
    public function getFirstError() : ?Error
32
    {
33
        if (!$this->valid) {
34
            return $this->errors[0];
35
        }
36
        return null;
37
    }
38
}