Completed
Push — master ( 02ce25...4c3a23 )
by Alex
14s queued 11s
created

Result::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
4
namespace FeedIo\Command;
5
6
/**
7
 * Class Result
8
 * @codeCoverageIgnore
9
 */
10
class Result
11
{
12
    const TEST_UNIQUE_IDS = 'unique_ids';
13
14
    const TEST_NORMAL_DATE_FLOW = 'normal_date_flow';
15
16
    const TEST_JAN_1970 = 'jan_1970';
17
18
    const TEST_1YEAR_OLD = '1year_old';
19
20
    const TEST_EMPTY_FUTURE = 'empty_future';
21
22
    private $url;
23
24
    private $modifiedSince = 'null';
25
26
    private $itemCount = 0;
27
28
    private $accessible = true;
29
30
    private $updateable = true;
31
32
    private $tests = [
33
        self::TEST_UNIQUE_IDS => true,
34
        self::TEST_NORMAL_DATE_FLOW => true,
35
        self::TEST_JAN_1970 => true,
36
        self::TEST_1YEAR_OLD => true,
37
        self::TEST_EMPTY_FUTURE => true,
38
    ];
39
40
    public function __construct(string $url)
41
    {
42
        $this->url = $url;
43
    }
44
45
    public function setNotAccessible(): self
46
    {
47
        $this->accessible = false;
48
        $this->markAllAsFailed();
49
50
        return $this;
51
    }
52
53
    public function isUpdateable(): bool
54
    {
55
        return $this->updateable;
56
    }
57
58
    public function setNotUpdateable(): Result
59
    {
60
        $this->updateable = false;
61
        $this->markAllAsFailed();
62
63
        return $this;
64
    }
65
66
    public function setModifiedSince(\DateTime $modifiedSince): self
67
    {
68
        $this->modifiedSince = $modifiedSince->format(\DATE_ATOM);
69
        return $this;
70
    }
71
72
    public function setItemCount(int $itemCount): self
73
    {
74
        $this->itemCount = $itemCount;
75
        return $this;
76
    }
77
78
    protected function markAllAsFailed(): void
79
    {
80
        foreach ($this->tests as $test => $value) {
81
            $this->markAsFailed($test);
82
        }
83
    }
84
85
    public function markAsFailed(string $test): self
86
    {
87
        $this->tests[$test] = false;
88
        return $this;
89
    }
90
91
    public function toArray(): array
92
    {
93
        return [
94
            $this->url,
95
            $this->accessible,
96
            $this->updateable,
97
            $this->modifiedSince,
98
            $this->itemCount,
99
            $this->tests[self::TEST_UNIQUE_IDS],
100
            $this->tests[self::TEST_NORMAL_DATE_FLOW],
101
            $this->tests[self::TEST_JAN_1970],
102
            $this->tests[self::TEST_1YEAR_OLD],
103
            $this->tests[self::TEST_EMPTY_FUTURE],
104
        ];
105
    }
106
}
107