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

Result::getFirstError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
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
}