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