Skip to content

Commit 8f03ca3

Browse files
More refactoring
1 parent 9ca8c10 commit 8f03ca3

File tree

2 files changed

+208
-62
lines changed

2 files changed

+208
-62
lines changed

src/Literals/Literal.php

Lines changed: 204 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public static function dateTime($timezone = null): DateTimeType
263263
*/
264264
public static function dateTimeYMD($year, $month = null, $day = null, $hour = null, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null, $timezone = null): DateTimeType
265265
{
266-
$setVariables = self::checkOrderAndConvertToNumeral([
266+
$variables = self::checkOrderAndConvertToNumeral([
267267
"month"=> $month,
268268
"day" => $day,
269269
"hour" => $hour,
@@ -280,18 +280,43 @@ public static function dateTimeYMD($year, $month = null, $day = null, $hour = nu
280280

281281
$map = ["year" => $year];
282282

283-
if ($month !== null) $map["month"] = $setVariables["month"];
284-
if ($day !== null) $map["day"] = $setVariables["day"];
285-
if ($hour !== null) $map["hour"] = $setVariables["hour"];
286-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
287-
if ($second !== null) $map["second"] = $setVariables["second"];
288-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
289-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
290-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
283+
if ($month !== null) {
284+
$map["month"] = $variables["month"];
285+
}
286+
287+
if ($day !== null) {
288+
$map["day"] = $variables["day"];
289+
}
290+
291+
if ($hour !== null) {
292+
$map["hour"] = $variables["hour"];
293+
}
294+
295+
if ($minute !== null) {
296+
$map["minute"] = $variables["minute"];
297+
}
298+
299+
if ($second !== null) {
300+
$map["second"] = $variables["second"];
301+
}
302+
303+
if ($millisecond !== null) {
304+
$map["millisecond"] = $variables["millisecond"];
305+
}
306+
307+
if ($microsecond !== null) {
308+
$map["microsecond"] = $variables["microsecond"];
309+
}
310+
311+
if ($nanosecond !== null) {
312+
$map["nanosecond"] = $variables["nanosecond"];
313+
}
314+
291315
if ($timezone !== null) {
292316
if (!($timezone instanceof StringType)) {
293317
$timezone = self::string($timezone);
294318
}
319+
295320
$map["timezone"] = $timezone;
296321
}
297322

@@ -576,7 +601,7 @@ public static function localDatetime($timezone = null): LocalDateTimeType {
576601
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-calendar
577602
*/
578603
public static function localDatetimeYMD($year, $month = null, $day = null, $hour = null, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null): LocalDateTimeType {
579-
$setVariables = self::checkOrderAndConvertToNumeral([
604+
$variables = self::checkOrderAndConvertToNumeral([
580605
"month" => $month,
581606
"day" => $day,
582607
"hour" => $hour,
@@ -593,14 +618,37 @@ public static function localDatetimeYMD($year, $month = null, $day = null, $hour
593618

594619
$map = ["year" => $year];
595620

596-
if ($month !== null) $map["month"] = $setVariables["month"];
597-
if ($day !== null) $map["day"] = $setVariables["day"];
598-
if ($hour !== null) $map["hour"] = $setVariables["hour"];
599-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
600-
if ($second !== null) $map["second"] = $setVariables["second"];
601-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
602-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
603-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
621+
if ($month !== null) {
622+
$map["month"] = $variables["month"];
623+
}
624+
625+
if ($day !== null) {
626+
$map["day"] = $variables["day"];
627+
}
628+
629+
if ($hour !== null) {
630+
$map["hour"] = $variables["hour"];
631+
}
632+
633+
if ($minute !== null) {
634+
$map["minute"] = $variables["minute"];
635+
}
636+
637+
if ($second !== null) {
638+
$map["second"] = $variables["second"];
639+
}
640+
641+
if ($millisecond !== null) {
642+
$map["millisecond"] = $variables["millisecond"];
643+
}
644+
645+
if ($microsecond !== null) {
646+
$map["microsecond"] = $variables["microsecond"];
647+
}
648+
649+
if ($nanosecond !== null) {
650+
$map["nanosecond"] = $variables["nanosecond"];
651+
}
604652

605653
return FunctionCall::localdatetime(Query::map($map));
606654
}
@@ -623,7 +671,7 @@ public static function localDatetimeYMD($year, $month = null, $day = null, $hour
623671
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-week
624672
*/
625673
public static function localDatetimeYWD($year, $week = null, $dayOfWeek = null, $hour = null, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null): LocalDateTimeType {
626-
$setVariables = self::checkOrderAndConvertToNumeral([
674+
$variables = self::checkOrderAndConvertToNumeral([
627675
"week" => $week,
628676
"dayOfWeek" => $dayOfWeek,
629677
"hour" => $hour,
@@ -640,14 +688,37 @@ public static function localDatetimeYWD($year, $week = null, $dayOfWeek = null,
640688

641689
$map = ["year" => $year];
642690

643-
if ($week !== null) $map["week"] = $setVariables["week"];
644-
if ($dayOfWeek !== null) $map["dayOfWeek"] = $setVariables["dayOfWeek"];
645-
if ($hour !== null) $map["hour"] = $setVariables["hour"];
646-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
647-
if ($second !== null) $map["second"] = $setVariables["second"];
648-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
649-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
650-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
691+
if ($week !== null) {
692+
$map["week"] = $variables["week"];
693+
}
694+
695+
if ($dayOfWeek !== null) {
696+
$map["dayOfWeek"] = $variables["dayOfWeek"];
697+
}
698+
699+
if ($hour !== null) {
700+
$map["hour"] = $variables["hour"];
701+
}
702+
703+
if ($minute !== null) {
704+
$map["minute"] = $variables["minute"];
705+
}
706+
707+
if ($second !== null) {
708+
$map["second"] = $variables["second"];
709+
}
710+
711+
if ($millisecond !== null) {
712+
$map["millisecond"] = $variables["millisecond"];
713+
}
714+
715+
if ($microsecond !== null) {
716+
$map["microsecond"] = $variables["microsecond"];
717+
}
718+
719+
if ($nanosecond !== null) {
720+
$map["nanosecond"] = $variables["nanosecond"];
721+
}
651722

652723
return FunctionCall::localdatetime(Query::map($map));
653724
}
@@ -669,7 +740,7 @@ public static function localDatetimeYWD($year, $week = null, $dayOfWeek = null,
669740
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-quarter
670741
*/
671742
public static function localDatetimeYQD($year, $quarter = null, $dayOfQuarter = null, $hour = null, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null): LocalDateTimeType {
672-
$setVariables = self::checkOrderAndConvertToNumeral([
743+
$variables = self::checkOrderAndConvertToNumeral([
673744
"quarter" => $quarter,
674745
"dayOfQuarter" => $dayOfQuarter,
675746
"hour" => $hour,
@@ -686,14 +757,37 @@ public static function localDatetimeYQD($year, $quarter = null, $dayOfQuarter =
686757

687758
$map = ["year" => $year];
688759

689-
if ($quarter !== null) $map["quarter"] = $setVariables["quarter"];
690-
if ($dayOfQuarter !== null) $map["dayOfQuarter"] = $setVariables["dayOfQuarter"];
691-
if ($hour !== null) $map["hour"] = $setVariables["hour"];
692-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
693-
if ($second !== null) $map["second"] = $setVariables["second"];
694-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
695-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
696-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
760+
if ($quarter !== null) {
761+
$map["quarter"] = $variables["quarter"];
762+
}
763+
764+
if ($dayOfQuarter !== null) {
765+
$map["dayOfQuarter"] = $variables["dayOfQuarter"];
766+
}
767+
768+
if ($hour !== null) {
769+
$map["hour"] = $variables["hour"];
770+
}
771+
772+
if ($minute !== null) {
773+
$map["minute"] = $variables["minute"];
774+
}
775+
776+
if ($second !== null) {
777+
$map["second"] = $variables["second"];
778+
}
779+
780+
if ($millisecond !== null) {
781+
$map["millisecond"] = $variables["millisecond"];
782+
}
783+
784+
if ($microsecond !== null) {
785+
$map["microsecond"] = $variables["microsecond"];
786+
}
787+
788+
if ($nanosecond !== null) {
789+
$map["nanosecond"] = $variables["nanosecond"];
790+
}
697791

698792
return FunctionCall::localdatetime(Query::map($map));
699793
}
@@ -714,7 +808,7 @@ public static function localDatetimeYQD($year, $quarter = null, $dayOfQuarter =
714808
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-ordinal
715809
*/
716810
public static function localDatetimeYD($year, $ordinalDay = null, $hour = null, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null): LocalDateTimeType {
717-
$setVariables = self::checkOrderAndConvertToNumeral([
811+
$variables = self::checkOrderAndConvertToNumeral([
718812
"ordinalDay" => $ordinalDay,
719813
"hour" => $hour,
720814
"minute" => $minute,
@@ -730,13 +824,33 @@ public static function localDatetimeYD($year, $ordinalDay = null, $hour = null,
730824

731825
$map = ["year" => $year];
732826

733-
if ($ordinalDay !== null) $map["ordinalDay"] = $setVariables["ordinalDay"];
734-
if ($hour !== null) $map["hour"] = $setVariables["hour"];
735-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
736-
if ($second !== null) $map["second"] = $setVariables["second"];
737-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
738-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
739-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
827+
if ($ordinalDay !== null) {
828+
$map["ordinalDay"] = $variables["ordinalDay"];
829+
}
830+
831+
if ($hour !== null) {
832+
$map["hour"] = $variables["hour"];
833+
}
834+
835+
if ($minute !== null) {
836+
$map["minute"] = $variables["minute"];
837+
}
838+
839+
if ($second !== null) {
840+
$map["second"] = $variables["second"];
841+
}
842+
843+
if ($millisecond !== null) {
844+
$map["millisecond"] = $variables["millisecond"];
845+
}
846+
847+
if ($microsecond !== null) {
848+
$map["microsecond"] = $variables["microsecond"];
849+
}
850+
851+
if ($nanosecond !== null) {
852+
$map["nanosecond"] = $variables["nanosecond"];
853+
}
740854

741855
return FunctionCall::localdatetime(Query::map($map));
742856
}
@@ -790,7 +904,7 @@ public static function localTimeCurrent($timezone = null): LocalTimeType {
790904
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-create
791905
*/
792906
public static function localTime($hour, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null): LocalTimeType {
793-
$setVariables = self::checkOrderAndConvertToNumeral([
907+
$variables = self::checkOrderAndConvertToNumeral([
794908
"minute" => $minute,
795909
"second" => $second,
796910
"millisecond" => $millisecond,
@@ -804,11 +918,25 @@ public static function localTime($hour, $minute = null, $second = null, $millise
804918

805919
$map = ["hour" => $hour];
806920

807-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
808-
if ($second !== null) $map["second"] = $setVariables["second"];
809-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
810-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
811-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
921+
if ($minute !== null) {
922+
$map["minute"] = $variables["minute"];
923+
}
924+
925+
if ($second !== null) {
926+
$map["second"] = $variables["second"];
927+
}
928+
929+
if ($millisecond !== null) {
930+
$map["millisecond"] = $variables["millisecond"];
931+
}
932+
933+
if ($microsecond !== null) {
934+
$map["microsecond"] = $variables["microsecond"];
935+
}
936+
937+
if ($nanosecond !== null) {
938+
$map["nanosecond"] = $variables["nanosecond"];
939+
}
812940

813941
return FunctionCall::localtime(Query::map($map));
814942
}
@@ -835,14 +963,15 @@ public static function localTimeString($localTimeString): LocalTimeType {
835963
*
836964
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-current
837965
*/
838-
public static function timeCurrent($timezone = null): TimeType {
966+
public static function time($timezone = null): TimeType {
839967
if ($timezone === null) {
840968
return FunctionCall::time();
841969
}
842970

843971
if (!($timezone instanceof StringType)) {
844972
$timezone = self::string($timezone);
845973
}
974+
846975
return FunctionCall::time(Query::map(["timezone" => $timezone]));
847976
}
848977

@@ -860,8 +989,8 @@ public static function timeCurrent($timezone = null): TimeType {
860989
*
861990
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-create
862991
*/
863-
public static function time($hour, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null, $timezone = null): TimeType {
864-
$setVariables = self::checkOrderAndConvertToNumeral([
992+
public static function timeHMS($hour, $minute = null, $second = null, $millisecond = null, $microsecond = null, $nanosecond = null, $timezone = null): TimeType {
993+
$variables = self::checkOrderAndConvertToNumeral([
865994
"minute" => $minute,
866995
"second" => $second,
867996
"millisecond" => $millisecond,
@@ -875,15 +1004,31 @@ public static function time($hour, $minute = null, $second = null, $millisecond
8751004

8761005
$map = ["hour" => $hour];
8771006

878-
if ($minute !== null) $map["minute"] = $setVariables["minute"];
879-
if ($second !== null) $map["second"] = $setVariables["second"];
880-
if ($millisecond !== null) $map["millisecond"] = $setVariables["millisecond"];
881-
if ($microsecond !== null) $map["microsecond"] = $setVariables["microsecond"];
882-
if ($nanosecond !== null) $map["nanosecond"] = $setVariables["nanosecond"];
1007+
if ($minute !== null) {
1008+
$map["minute"] = $variables["minute"];
1009+
}
1010+
1011+
if ($second !== null) {
1012+
$map["second"] = $variables["second"];
1013+
}
1014+
1015+
if ($millisecond !== null) {
1016+
$map["millisecond"] = $variables["millisecond"];
1017+
}
1018+
1019+
if ($microsecond !== null) {
1020+
$map["microsecond"] = $variables["microsecond"];
1021+
}
1022+
1023+
if ($nanosecond !== null) {
1024+
$map["nanosecond"] = $variables["nanosecond"];
1025+
}
1026+
8831027
if ($timezone !== null) {
8841028
if (!($timezone instanceof StringType)) {
8851029
$timezone = self::string($timezone);
8861030
}
1031+
8871032
$map["timezone"] = $timezone;
8881033
}
8891034

@@ -902,6 +1047,7 @@ public static function timeString($timeString): TimeType {
9021047
if (!($timeString instanceof StringType)) {
9031048
$timeString = self::string($timeString);
9041049
}
1050+
9051051
return FunctionCall::time($timeString);
9061052
}
9071053

0 commit comments

Comments
 (0)