Passed
Push — master ( 5f9e30...9e7e6b )
by Dedipyaman
02:07
created

Result   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 3 1
A __construct() 0 4 1
A getFirstError() 0 6 2
A getErrors() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: dedipyaman
5
 * Date: 1/23/19
6
 * Time: 2:07 AM
7
 */
8
9
namespace Phypes;
10
11
use Phypes\Error\Error;
12
13
class Result
14
{
15
    private $valid;
16
    private $errors = [];
17
18
    public function __construct(bool $valid, Error... $errors)
19
    {
20
        $this->valid = $valid;
21
        $this->errors = $errors;
22
    }
23
24
    public function isValid() : bool
25
    {
26
        return $this->valid;
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function getErrors(): array
33
    {
34
35
        return $this->errors;
36
    }
37
38
    public function getFirstError() : ?Error
39
    {
40
        if (!$this->valid) {
41
            return $this->errors[0];
42
        }
43
        return null;
44
    }
45
}