From 3b31c5c5eaa6f5d37bf7c265c6cb47cf7c910b48 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 1 Dec 2024 16:49:43 +0000 Subject: [PATCH] nah too much work, cba lol --- .../LinkQuery/Building/LinkQuery_Step1.php | 20 ---- .../LinkQuery/Building/LinkQuery_Step2.php | 31 ----- .../LinkQuery/Building/LinkQuery_Step3.php | 31 ----- .../LinkQuery/Building/LinkQuery_Step4.php | 40 ------- .../LinkQuery/Building/LinkQuery_Step9.php | 25 ----- .../LinkQuery/LinkQueryBuilder.php | 106 ++++++++++++++++++ src/QueryBuilder/QueryBuilder.php | 5 +- tests/QueryBuilderLinkTest.php | 42 +++---- 8 files changed, 130 insertions(+), 170 deletions(-) delete mode 100644 src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php delete mode 100644 src/QueryBuilder/LinkQuery/Building/LinkQuery_Step2.php delete mode 100644 src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php delete mode 100644 src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php delete mode 100644 src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php create mode 100644 src/QueryBuilder/LinkQuery/LinkQueryBuilder.php diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php deleted file mode 100644 index f333268..0000000 --- a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step1.php +++ /dev/null @@ -1,20 +0,0 @@ -QuerySoFar = $querySoFar; - } - - public function To(string $relativePath): LinkQuery_Step3 - { - self::ValidateDeegraphPath(target: $relativePath); - return new LinkQuery_Step3($this->QuerySoFar . " TO " . $relativePath); - } - - public function Of(string $relativePath): LinkQuery_Step3 - { - self::ValidateDeegraphPath(target: $relativePath); - return new LinkQuery_Step3($this->QuerySoFar . " OF " . $relativePath); - } -} \ No newline at end of file diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php deleted file mode 100644 index 5779d2d..0000000 --- a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step3.php +++ /dev/null @@ -1,31 +0,0 @@ -QuerySoFar = $querySoFar; - } - - public function As(string $asPropertyName): LinkQuery_Step4 - { - self::ValidateDeegraphPath(target: $asPropertyName); - return new LinkQuery_Step4($this->QuerySoFar . " AS " . $asPropertyName); - } - - public function Build(): LinkQuery - { - return new LinkQuery($this->QuerySoFar); - } -} diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php deleted file mode 100644 index a9d0b14..0000000 --- a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step4.php +++ /dev/null @@ -1,40 +0,0 @@ -QuerySoFar = $querySoFar; - } - - public function Overwrite(): LinkQuery_Step9 - { - return new LinkQuery_Step9($this->QuerySoFar . " OVERWRITE"); - } - - public function Replace(): LinkQuery_Step9 - { - return new LinkQuery_Step9($this->QuerySoFar . " REPLACE"); - } - - public function Force(): LinkQuery_Step9 - { - return new LinkQuery_Step9($this->QuerySoFar . " FORCE"); - } - - public function Build(): LinkQuery - { - return new LinkQuery($this->QuerySoFar); - } -} diff --git a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php b/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php deleted file mode 100644 index 83f002d..0000000 --- a/src/QueryBuilder/LinkQuery/Building/LinkQuery_Step9.php +++ /dev/null @@ -1,25 +0,0 @@ -QuerySoFar = $querySoFar; - } - - public function Build() - { - return new LinkQuery($this->QuerySoFar); - } -} diff --git a/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php b/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php new file mode 100644 index 0000000..6301493 --- /dev/null +++ b/src/QueryBuilder/LinkQuery/LinkQueryBuilder.php @@ -0,0 +1,106 @@ +RelativePath1 = $relativePath; + return $this; + } + public function LinkTo(string $relativePath): LinkQueryBuilder + { + self::EnsureNotSet($this->RelativePath2); + self::ValidateDeegraphPath(target: $relativePath); + $this->RelativePath2 = $relativePath; + $this->ToOrOf = "TO"; + return $this; + } + public function LinkOf(string $relativePath): LinkQueryBuilder + { + self::EnsureNotSet($this->RelativePath2); + self::ValidateDeegraphPath(target: $relativePath); + $this->RelativePath2 = $relativePath; + $this->ToOrOf = "OF"; + return $this; + } + + + + public function PropertyName(string $propertyName): LinkQueryBuilder + { + $this->PropertyName = $propertyName; + return $this; + } + + + + public function Overwrite(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "OVERWRITE"; + return $this; + } + public function Replace(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "REPLACE"; + return $this; + } + public function Force(): LinkQueryBuilder + { + self::EnsureNotSet($this->Mode); + $this->Mode = "FORCE"; + return $this; + } + + + + public function Build(): LinkQuery + { + self::ValidateValues(target: $this); + + $builder = "LINK " + . $this->RelativePath1 + . " " + . $this->ToOrOf + . " " + . $this->RelativePath2 + . " AS " + . $this->PropertyName; + + if($this->Mode != "") $builder .= " " . $this->Mode; + + return new LinkQuery(queryString: $builder); + } +} + diff --git a/src/QueryBuilder/QueryBuilder.php b/src/QueryBuilder/QueryBuilder.php index e268f64..2fbbdf4 100755 --- a/src/QueryBuilder/QueryBuilder.php +++ b/src/QueryBuilder/QueryBuilder.php @@ -5,7 +5,6 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DeleteQuery\DeleteQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery; -use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\Building\LinkQuery_Step1; use Darksparrow\DeegraphInteractions\QueryBuilder\LinkQuery\LinkQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder; use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder; @@ -39,9 +38,9 @@ final class QueryBuilder { return new ReferencesQueryBuilder(); } - public static function Link(): LinkQuery_Step1 + public static function Link(): LinkQueryBuilder { - return new LinkQuery_Step1(); + return new LinkQueryBuilder(); } public static function Unlink(): UnlinkQueryBuilder { diff --git a/tests/QueryBuilderLinkTest.php b/tests/QueryBuilderLinkTest.php index e841357..09f74c5 100644 --- a/tests/QueryBuilderLinkTest.php +++ b/tests/QueryBuilderLinkTest.php @@ -14,9 +14,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->To($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") ->Build() ); } @@ -25,9 +25,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test OVERWRITE", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->To($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") ->Overwrite() ->Build() ); @@ -37,9 +37,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test REPLACE", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->To($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") ->Replace() ->Build() ); @@ -49,9 +49,9 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} TO {$this->TestUUID} AS test FORCE", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->To($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkTo($this->TestUUID) + ->PropertyName("test") ->Force() ->Build() ); @@ -61,23 +61,25 @@ final class QueryBuilderLinkTest extends TestCase self::assertEquals( expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->Of($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkOf($this->TestUUID) + ->PropertyName("test") ->Build() ); } - /* public function test5() { self::expectException(QueryBuilderConflictingFieldAlreadyExistsException::class); self::assertEquals( expected: "LINK {$this->TestUUID} OF {$this->TestUUID} AS test", actual: QueryBuilder::Link() - ->RelativePath($this->TestUUID) - ->Of($this->TestUUID) - ->As("test") + ->LinkWhat($this->TestUUID) + ->LinkOf($this->TestUUID) + ->PropertyName("test") + ->Overwrite() + ->Replace() + ->Force() + ->Build() ); } - */ }