Test Setup Failed
Push — master ( 299946...d1af9f )
by Christian
08:55
created

AbstractResult.php$0 ➔ getErrors()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RemotelyLiving\PHPQueryBus;
6
7
use RemotelyLiving\PHPQueryBus\Interfaces;
8
9
abstract class AbstractResult implements Interfaces\Result
10
{
11
    final public function isNotFound(): bool
12
    {
13
        return false;
14
    }
15
16
    final public function getErrors(): iterable
17
    {
18
        return [];
19
    }
20
21
    final public function hasErrors(): bool
22
    {
23
        return false;
24
    }
25
26
    final public static function notFound(): Interfaces\Result
27
    {
28
        return new class implements Interfaces\Result
29
        {
30
            public function isNotFound(): bool
31
            {
32
                return true;
33
            }
34
35
            public function getErrors(): iterable
36
            {
37
                return [];
38
            }
39
40
            public function hasErrors(): bool
41
            {
42
                return false;
43
            }
44
        };
45
    }
46
47
    final public static function withErrors(\Throwable ...$errors): Interfaces\Result
48
    {
49
        return new class (...$errors) implements Interfaces\Result
50
        {
51
            private array $errors = [];
52
53
            public function __construct(\Throwable ...$errors)
54
            {
55
                $this->errors = $errors;
56
            }
57
58
            public function isNotFound(): bool
59
            {
60
                return false;
61
            }
62
63
            public function getErrors(): iterable
64
            {
65
                return $this->errors;
66
            }
67
68
            public function hasErrors(): bool
69
            {
70
                return true;
71
            }
72
        };
73
    }
74
}
75