88use Kirby \Filesystem \F ;
99use Kirby \Toolkit \Collection ;
1010use Kirby \Toolkit \I18n ;
11- use Kirby \Toolkit \Properties ;
1211
1312/**
1413 * Version
2221 */
2322class Version
2423{
25- use Properties;
26-
2724 /**
2825 * Commit hash of this version
2926 */
@@ -32,17 +29,17 @@ class Version
3229 /**
3330 * Creation timestamp
3431 */
35- protected int |null $ created = null ;
32+ protected int |null $ created ;
3633
3734 /**
3835 * Email address of the creator
3936 */
40- protected string |null $ creatorEmail = null ;
37+ protected string |null $ creatorEmail ;
4138
4239 /**
4340 * Name of the creator
4441 */
45- protected string |null $ creatorName = null ;
42+ protected string |null $ creatorName ;
4643
4744 /**
4845 * Custom label
@@ -58,7 +55,7 @@ class Version
5855 * Name of the instance where the version was
5956 * originally created
6057 */
61- protected string |null $ originInstance = null ;
58+ protected string |null $ originInstance ;
6259
6360 /**
6461 * Instance of the Plugin class
@@ -70,7 +67,14 @@ class Version
7067 */
7168 public function __construct (array $ props )
7269 {
73- $ this ->setProperties ($ props );
70+ $ this ->commit = $ props ['commit ' ];
71+ $ this ->created = $ this ->normalizeCreated ($ props ['created ' ] ?? null );
72+ $ this ->creatorEmail = $ this ->normalizeCreatorEmail ($ props ['creatorEmail ' ] ?? null );
73+ $ this ->creatorName = $ this ->normalizeCreatorName ($ props ['creatorName ' ] ?? null );
74+ $ this ->label = $ props ['label ' ];
75+ $ this ->name = $ props ['name ' ];
76+ $ this ->originInstance = $ props ['originInstance ' ] ?? null ;
77+ $ this ->plugin = $ props ['plugin ' ];
7478 }
7579
7680 /**
@@ -229,26 +233,22 @@ public function originInstance(): string|null
229233 */
230234 public function toArray (): array
231235 {
232- $ array = $ this ->propertiesToArray ();
233- $ array ['instances ' ] = $ this ->instances ()->keys ();
234-
235- ksort ($ array );
236- return $ array ;
237- }
238-
239- /**
240- * Sets the commit hash of this version
241- */
242- protected function setCommit (string $ commit ): self
243- {
244- $ this ->commit = $ commit ;
245- return $ this ;
236+ return [
237+ 'commit ' => $ this ->commit (),
238+ 'created ' => $ this ->created (),
239+ 'creatorEmail ' => $ this ->creatorEmail (),
240+ 'creatorName ' => $ this ->creatorName (),
241+ 'instances ' => $ this ->instances ()->keys (),
242+ 'label ' => $ this ->label (),
243+ 'name ' => $ this ->name (),
244+ 'originInstance ' => $ this ->originInstance (),
245+ ];
246246 }
247247
248248 /**
249- * Sets the creation timestamp
249+ * Normalizes the creation timestamp for the property
250250 */
251- protected function setCreated (int |string |null $ created = null ): self
251+ protected function normalizeCreated (int |string |null $ created ): int | null
252252 {
253253 if (is_string ($ created ) === true ) {
254254 $ created = $ created ? strtotime ($ created ) : null ;
@@ -261,76 +261,34 @@ protected function setCreated(int|string|null $created = null): self
261261 ]);
262262 }
263263
264- $ this ->created = $ created ;
265- return $ this ;
264+ return $ created ;
266265 }
267266
268267 /**
269- * Sets the email address of the creator
268+ * Normalizes the email address of the creator for the property
270269 */
271- protected function setCreatorEmail (string |null $ creatorEmail = null ): self
270+ protected function normalizeCreatorEmail (string |null $ creatorEmail ): string | null
272271 {
273272 // Git will output an empty string if the value is not available
274- if ($ creatorEmail === '' ) {
275- $ creatorEmail = null ;
276- } elseif ($ creatorEmail !== null ) {
277- // trim the angle brackets around the email address
278- // that come from Git's output
279- $ creatorEmail = trim ($ creatorEmail , '<> ' );
273+ if ($ creatorEmail === '' || $ creatorEmail === null ) {
274+ return null ;
280275 }
281276
282- $ this ->creatorEmail = $ creatorEmail ;
283- return $ this ;
277+ // trim the angle brackets around the email address
278+ // that come from Git's output
279+ return trim ($ creatorEmail , '<> ' );
284280 }
285281
286282 /**
287- * Sets the name of the creator
283+ * Normalizes the name of the creator for the property
288284 */
289- protected function setCreatorName (string |null $ creatorName = null ): self
285+ protected function normalizeCreatorName (string |null $ creatorName ): string | null
290286 {
291287 // Git will output an empty string if the value is not available
292288 if ($ creatorName === '' ) {
293- $ creatorName = null ;
289+ return null ;
294290 }
295291
296- $ this ->creatorName = $ creatorName ;
297- return $ this ;
298- }
299-
300- /**
301- * Sets the custom label
302- */
303- protected function setLabel (string $ label ): self
304- {
305- $ this ->label = $ label ;
306- return $ this ;
307- }
308-
309- /**
310- * Sets the unique version name
311- */
312- protected function setName (string $ name ): self
313- {
314- $ this ->name = $ name ;
315- return $ this ;
316- }
317-
318- /**
319- * Sets the name of the instance where
320- * the version was originally created
321- */
322- protected function setOriginInstance (string |null $ originInstance = null ): self
323- {
324- $ this ->originInstance = $ originInstance ;
325- return $ this ;
326- }
327-
328- /**
329- * Sets the instance of the Plugin class
330- */
331- protected function setPlugin (Plugin $ plugin ): self
332- {
333- $ this ->plugin = $ plugin ;
334- return $ this ;
292+ return $ creatorName ;
335293 }
336294}
0 commit comments