@@ -263,7 +263,7 @@ public static function dateTime($timezone = null): DateTimeType
263
263
*/
264
264
public static function dateTimeYMD ($ year , $ month = null , $ day = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null , $ timezone = null ): DateTimeType
265
265
{
266
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
266
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
267
267
"month " => $ month ,
268
268
"day " => $ day ,
269
269
"hour " => $ hour ,
@@ -298,35 +298,6 @@ public static function dateTimeYMD($year, $month = null, $day = null, $hour = nu
298
298
return FunctionCall::datetime (Query::map ($ map ));
299
299
}
300
300
301
- /**
302
- * checks the order of the array items, and converts the items to NumeralType
303
- *
304
- * @param array $array
305
- * @return array
306
- */
307
- private static function checkOrderAndConvert2Numeral (array $ array ): array {
308
- $ previous = true ;
309
-
310
- foreach ($ array as $ key => $ setVariable ) {
311
- // Only the least significant components may be omitted; check whether this is the case
312
- if (isset ($ setVariable ) === true && $ previous === false ) {
313
- throw new \LogicException ("Only the least significant components may be omitted " );
314
- }
315
-
316
- // check if variable has been set and convert always to NumeralType
317
- if (isset ($ setVariable )) {
318
- if (!($ setVariable instanceof NumeralType)) {
319
- $ setVariable = self ::decimal ($ setVariable );
320
- $ array [$ key ] = $ setVariable ;
321
- }
322
- }
323
-
324
- $ previous = isset ($ setVariable );
325
- }
326
-
327
- return $ array ;
328
- }
329
-
330
301
/**
331
302
* Creates a datetime with the specified year, week, dayOfWeek, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
332
303
*
@@ -346,7 +317,7 @@ private static function checkOrderAndConvert2Numeral(array $array): array {
346
317
*/
347
318
public static function datetimeYWD ($ year , $ week = null , $ dayOfWeek = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null , $ timezone = null ): DateTimeType
348
319
{
349
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
320
+ $ variables = self ::checkOrderAndConvertToNumeral ([
350
321
"week " => $ week ,
351
322
"dayOfWeek " => $ dayOfWeek ,
352
323
"hour " => $ hour ,
@@ -363,18 +334,43 @@ public static function datetimeYWD($year, $week = null, $dayOfWeek = null, $hour
363
334
364
335
$ map = ["year " => $ year ];
365
336
366
- if ($ week !== null ) $ map ["week " ] = $ setVariables ["week " ];
367
- if ($ dayOfWeek !== null ) $ map ["dayOfWeek " ] = $ setVariables ["dayOfWeek " ];
368
- if ($ hour !== null ) $ map ["hour " ] = $ setVariables ["hour " ];
369
- if ($ minute !== null ) $ map ["minute " ] = $ setVariables ["minute " ];
370
- if ($ second !== null ) $ map ["second " ] = $ setVariables ["second " ];
371
- if ($ millisecond !== null ) $ map ["millisecond " ] = $ setVariables ["millisecond " ];
372
- if ($ microsecond !== null ) $ map ["microsecond " ] = $ setVariables ["microsecond " ];
373
- if ($ nanosecond !== null ) $ map ["nanosecond " ] = $ setVariables ["nanosecond " ];
337
+ if ($ week !== null ) {
338
+ $ map ["week " ] = $ variables ["week " ];
339
+ }
340
+
341
+ if ($ dayOfWeek !== null ) {
342
+ $ map ["dayOfWeek " ] = $ variables ["dayOfWeek " ];
343
+ }
344
+
345
+ if ($ hour !== null ) {
346
+ $ map ["hour " ] = $ variables ["hour " ];
347
+ }
348
+
349
+ if ($ minute !== null ) {
350
+ $ map ["minute " ] = $ variables ["minute " ];
351
+ }
352
+
353
+ if ($ second !== null ) {
354
+ $ map ["second " ] = $ variables ["second " ];
355
+ }
356
+
357
+ if ($ millisecond !== null ) {
358
+ $ map ["millisecond " ] = $ variables ["millisecond " ];
359
+ }
360
+
361
+ if ($ microsecond !== null ) {
362
+ $ map ["microsecond " ] = $ variables ["microsecond " ];
363
+ }
364
+
365
+ if ($ nanosecond !== null ) {
366
+ $ map ["nanosecond " ] = $ variables ["nanosecond " ];
367
+ }
368
+
374
369
if ($ timezone !== null ) {
375
370
if (!($ timezone instanceof StringType)) {
376
371
$ timezone = self ::string ($ timezone );
377
372
}
373
+
378
374
$ map ["timezone " ] = $ timezone ;
379
375
}
380
376
@@ -399,7 +395,7 @@ public static function datetimeYWD($year, $week = null, $dayOfWeek = null, $hour
399
395
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-quarter
400
396
*/
401
397
public static function datetimeYQD ($ year , $ quarter = null , $ dayOfQuarter = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null , $ timezone = null ): DateTimeType {
402
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
398
+ $ variables = self ::checkOrderAndConvertToNumeral ([
403
399
"quarter " => $ quarter ,
404
400
"dayOfQuarter " => $ dayOfQuarter ,
405
401
"hour " => $ hour ,
@@ -416,18 +412,43 @@ public static function datetimeYQD($year, $quarter = null, $dayOfQuarter = null,
416
412
417
413
$ map = ["year " => $ year ];
418
414
419
- if ($ quarter !== null ) $ map ["quarter " ] = $ setVariables ["quarter " ];
420
- if ($ dayOfQuarter !== null ) $ map ["dayOfQuarter " ] = $ setVariables ["dayOfQuarter " ];
421
- if ($ hour !== null ) $ map ["hour " ] = $ setVariables ["hour " ];
422
- if ($ minute !== null ) $ map ["minute " ] = $ setVariables ["minute " ];
423
- if ($ second !== null ) $ map ["second " ] = $ setVariables ["second " ];
424
- if ($ millisecond !== null ) $ map ["millisecond " ] = $ setVariables ["millisecond " ];
425
- if ($ microsecond !== null ) $ map ["microsecond " ] = $ setVariables ["microsecond " ];
426
- if ($ nanosecond !== null ) $ map ["nanosecond " ] = $ setVariables ["nanosecond " ];
415
+ if ($ quarter !== null ) {
416
+ $ map ["quarter " ] = $ variables ["quarter " ];
417
+ }
418
+
419
+ if ($ dayOfQuarter !== null ) {
420
+ $ map ["dayOfQuarter " ] = $ variables ["dayOfQuarter " ];
421
+ }
422
+
423
+ if ($ hour !== null ) {
424
+ $ map ["hour " ] = $ variables ["hour " ];
425
+ }
426
+
427
+ if ($ minute !== null ) {
428
+ $ map ["minute " ] = $ variables ["minute " ];
429
+ }
430
+
431
+ if ($ second !== null ) {
432
+ $ map ["second " ] = $ variables ["second " ];
433
+ }
434
+
435
+ if ($ millisecond !== null ) {
436
+ $ map ["millisecond " ] = $ variables ["millisecond " ];
437
+ }
438
+
439
+ if ($ microsecond !== null ) {
440
+ $ map ["microsecond " ] = $ variables ["microsecond " ];
441
+ }
442
+
443
+ if ($ nanosecond !== null ) {
444
+ $ map ["nanosecond " ] = $ variables ["nanosecond " ];
445
+ }
446
+
427
447
if ($ timezone !== null ) {
428
448
if (!($ timezone instanceof StringType)) {
429
449
$ timezone = self ::string ($ timezone );
430
450
}
451
+
431
452
$ map ["timezone " ] = $ timezone ;
432
453
}
433
454
@@ -451,7 +472,7 @@ public static function datetimeYQD($year, $quarter = null, $dayOfQuarter = null,
451
472
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-ordinal
452
473
*/
453
474
public static function datetimeYD ($ year , $ ordinalDay = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null , $ timezone = null ): DateTimeType {
454
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
475
+ $ variables = self ::checkOrderAndConvertToNumeral ([
455
476
"ordinalDay " => $ ordinalDay ,
456
477
"hour " => $ hour ,
457
478
"minute " => $ minute ,
@@ -467,17 +488,39 @@ public static function datetimeYD($year, $ordinalDay = null, $hour = null, $minu
467
488
468
489
$ map = ["year " => $ year ];
469
490
470
- if ($ ordinalDay !== null ) $ map ["ordinalDay " ] = $ setVariables ["ordinalDay " ];
471
- if ($ hour !== null ) $ map ["hour " ] = $ setVariables ["hour " ];
472
- if ($ minute !== null ) $ map ["minute " ] = $ setVariables ["minute " ];
473
- if ($ second !== null ) $ map ["second " ] = $ setVariables ["second " ];
474
- if ($ millisecond !== null ) $ map ["millisecond " ] = $ setVariables ["millisecond " ];
475
- if ($ microsecond !== null ) $ map ["microsecond " ] = $ setVariables ["microsecond " ];
476
- if ($ nanosecond !== null ) $ map ["nanosecond " ] = $ setVariables ["nanosecond " ];
491
+ if ($ ordinalDay !== null ) {
492
+ $ map ["ordinalDay " ] = $ variables ["ordinalDay " ];
493
+ }
494
+
495
+ if ($ hour !== null ) {
496
+ $ map ["hour " ] = $ variables ["hour " ];
497
+ }
498
+
499
+ if ($ minute !== null ) {
500
+ $ map ["minute " ] = $ variables ["minute " ];
501
+ }
502
+
503
+ if ($ second !== null ) {
504
+ $ map ["second " ] = $ variables ["second " ];
505
+ }
506
+
507
+ if ($ millisecond !== null ) {
508
+ $ map ["millisecond " ] = $ variables ["millisecond " ];
509
+ }
510
+
511
+ if ($ microsecond !== null ) {
512
+ $ map ["microsecond " ] = $ variables ["microsecond " ];
513
+ }
514
+
515
+ if ($ nanosecond !== null ) {
516
+ $ map ["nanosecond " ] = $ variables ["nanosecond " ];
517
+ }
518
+
477
519
if ($ timezone !== null ) {
478
520
if (!($ timezone instanceof StringType)) {
479
521
$ timezone = self ::string ($ timezone );
480
522
}
523
+
481
524
$ map ["timezone " ] = $ timezone ;
482
525
}
483
526
@@ -533,7 +576,7 @@ public static function localDatetime($timezone = null): LocalDateTimeType {
533
576
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-calendar
534
577
*/
535
578
public static function localDatetimeYMD ($ year , $ month = null , $ day = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null ): LocalDateTimeType {
536
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
579
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
537
580
"month " => $ month ,
538
581
"day " => $ day ,
539
582
"hour " => $ hour ,
@@ -580,7 +623,7 @@ public static function localDatetimeYMD($year, $month = null, $day = null, $hour
580
623
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-week
581
624
*/
582
625
public static function localDatetimeYWD ($ year , $ week = null , $ dayOfWeek = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null ): LocalDateTimeType {
583
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
626
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
584
627
"week " => $ week ,
585
628
"dayOfWeek " => $ dayOfWeek ,
586
629
"hour " => $ hour ,
@@ -626,7 +669,7 @@ public static function localDatetimeYWD($year, $week = null, $dayOfWeek = null,
626
669
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-quarter
627
670
*/
628
671
public static function localDatetimeYQD ($ year , $ quarter = null , $ dayOfQuarter = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null ): LocalDateTimeType {
629
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
672
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
630
673
"quarter " => $ quarter ,
631
674
"dayOfQuarter " => $ dayOfQuarter ,
632
675
"hour " => $ hour ,
@@ -671,7 +714,7 @@ public static function localDatetimeYQD($year, $quarter = null, $dayOfQuarter =
671
714
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-ordinal
672
715
*/
673
716
public static function localDatetimeYD ($ year , $ ordinalDay = null , $ hour = null , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null ): LocalDateTimeType {
674
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
717
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
675
718
"ordinalDay " => $ ordinalDay ,
676
719
"hour " => $ hour ,
677
720
"minute " => $ minute ,
@@ -747,7 +790,7 @@ public static function localTimeCurrent($timezone = null): LocalTimeType {
747
790
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-create
748
791
*/
749
792
public static function localTime ($ hour , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null ): LocalTimeType {
750
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
793
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
751
794
"minute " => $ minute ,
752
795
"second " => $ second ,
753
796
"millisecond " => $ millisecond ,
@@ -818,7 +861,7 @@ public static function timeCurrent($timezone = null): TimeType {
818
861
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-create
819
862
*/
820
863
public static function time ($ hour , $ minute = null , $ second = null , $ millisecond = null , $ microsecond = null , $ nanosecond = null , $ timezone = null ): TimeType {
821
- $ setVariables = self ::checkOrderAndConvert2Numeral ([
864
+ $ setVariables = self ::checkOrderAndConvertToNumeral ([
822
865
"minute " => $ minute ,
823
866
"second " => $ second ,
824
867
"millisecond " => $ millisecond ,
@@ -993,4 +1036,34 @@ public static function point3dWGS84($longitude, $latitude, $height): PointType
993
1036
994
1037
return FunctionCall::point (Query::map ($ map ));
995
1038
}
1039
+
1040
+ /**
1041
+ * Checks the order of the array items, and converts the items to NumeralType.
1042
+ *
1043
+ * @param array $variables
1044
+ * @return array
1045
+ */
1046
+ private static function checkOrderAndConvertToNumeral (array $ variables ): array {
1047
+ $ previousExists = true ;
1048
+
1049
+ foreach ($ variables as $ key => $ variable ) {
1050
+ $ currentExists = $ variable !== null ;
1051
+
1052
+ // Only the least significant components may be omitted; check whether this is the case
1053
+ if ($ currentExists === true && $ previousExists === false ) {
1054
+ throw new \LogicException ("Only the least significant components may be omitted " );
1055
+ }
1056
+
1057
+ // Check if variable has been set and convert always to NumeralType
1058
+ if ($ currentExists ) {
1059
+ if (!($ variable instanceof NumeralType)) {
1060
+ $ variables [$ key ] = self ::decimal ($ variable );
1061
+ }
1062
+ }
1063
+
1064
+ $ previousExists = $ variable !== null ;
1065
+ }
1066
+
1067
+ return $ variables ;
1068
+ }
996
1069
}
0 commit comments