1 | <?php |
||
14 | class SitemapResourceBuilder |
||
15 | { |
||
16 | /** |
||
17 | * The title of the resource. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $title; |
||
22 | |||
23 | /** |
||
24 | * The absolute URL of where the resource can be accessed. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $location; |
||
29 | |||
30 | /** |
||
31 | * The date at which the resource was last modified. |
||
32 | * |
||
33 | * @var \DateTime |
||
34 | */ |
||
35 | protected $lastModified; |
||
36 | |||
37 | /** |
||
38 | * The change frequency at which this resource is updated. |
||
39 | * |
||
40 | * @see ChangeFrequencyEnum |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $changeFrequency; |
||
44 | |||
45 | /** |
||
46 | * The priority that this resource should be given within a sitemap. |
||
47 | * |
||
48 | * @var float |
||
49 | */ |
||
50 | protected $priority; |
||
51 | |||
52 | /** |
||
53 | * @var SitemapResourceValidator |
||
54 | */ |
||
55 | protected $validator; |
||
56 | |||
57 | /** |
||
58 | * The location prefix - used when creating resources |
||
59 | * with relative locations. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $locationPrefix; |
||
64 | |||
65 | /** |
||
66 | * SitemapResourceBuilder constructor. |
||
67 | * |
||
68 | * @param SitemapResourceValidator $validator |
||
69 | * @param string $locationPrefix |
||
70 | */ |
||
71 | 6 | public function __construct(SitemapResourceValidator $validator, string $locationPrefix) |
|
77 | |||
78 | /** |
||
79 | * Clear all of the builder properties to ensure a default state |
||
80 | * between multiple executions. |
||
81 | */ |
||
82 | 6 | private function clear() |
|
90 | |||
91 | /** |
||
92 | * Build an instance of a sitemap resource and validate it. |
||
93 | * |
||
94 | * @return SitemapResource |
||
95 | */ |
||
96 | 2 | public function build(): SitemapResource |
|
111 | |||
112 | /** |
||
113 | * @param string $title |
||
114 | * |
||
115 | * @return SitemapResourceBuilder |
||
116 | */ |
||
117 | 3 | public function withTitle(string $title): SitemapResourceBuilder |
|
123 | |||
124 | /** |
||
125 | * @param string $location |
||
126 | * |
||
127 | * @return SitemapResourceBuilder |
||
128 | */ |
||
129 | 1 | public function withAbsoluteLocation(string $location): SitemapResourceBuilder |
|
135 | |||
136 | /** |
||
137 | * @param string $location |
||
138 | * |
||
139 | * @return SitemapResourceBuilder |
||
140 | */ |
||
141 | 4 | public function withRelativeLocation(string $location): SitemapResourceBuilder |
|
147 | |||
148 | /** |
||
149 | * @param string $changeFrequency |
||
150 | * |
||
151 | * @return SitemapResourceBuilder |
||
152 | */ |
||
153 | 3 | public function withChangeFrequency(string $changeFrequency): SitemapResourceBuilder |
|
159 | |||
160 | /** |
||
161 | * @param \DateTime $lastModified |
||
162 | * |
||
163 | * @return SitemapResourceBuilder |
||
164 | */ |
||
165 | 3 | public function withLastModified(\DateTime $lastModified): SitemapResourceBuilder |
|
171 | |||
172 | /** |
||
173 | * @param float $priority |
||
174 | * |
||
175 | * @return SitemapResourceBuilder |
||
176 | */ |
||
177 | 3 | public function withPriority(float $priority): SitemapResourceBuilder |
|
183 | } |
||
184 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.