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

Result   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getErrors() 0 3 1
A getFirstError() 0 6 2
A __construct() 0 4 1
A isValid() 0 3 1
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
}