Skip to content

Commit b6517b1

Browse files
committed
merged main into qol
2 parents 6f9250f + d2e695e commit b6517b1

File tree

167 files changed

+1390
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+1390
-608
lines changed

src/Addition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ protected function getOperator(): string
4848
{
4949
return "+";
5050
}
51-
}
51+
}

src/AndOperator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ protected function getOperator(): string
4848
{
4949
return "AND";
5050
}
51-
}
51+
}

src/Assignment.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace WikibaseSolutions\CypherDSL;
2323

24-
use TypeError;
24+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2525
use WikibaseSolutions\CypherDSL\Types\AnyType;
2626

2727
/**
@@ -32,6 +32,8 @@
3232
*/
3333
class Assignment extends BinaryOperator
3434
{
35+
use ErrorTrait;
36+
3537
/**
3638
* @var bool Whether to use the property mutation instead of the property replacement
3739
* operator.
@@ -44,9 +46,7 @@ class Assignment extends BinaryOperator
4446
*/
4547
public function __construct(AnyType $left, AnyType $right)
4648
{
47-
if (!($left instanceof Property) && !($left instanceof Variable)) {
48-
throw new TypeError("\$left must be either a Property or a Variable");
49-
}
49+
$this->assertClass('left', [Property::class, Variable::class], $left);
5050

5151
parent::__construct($left, $right, false);
5252
}
@@ -82,4 +82,4 @@ protected function getOperator(): string
8282
{
8383
return $this->mutate ? "+=" : "=";
8484
}
85-
}
85+
}

src/BinaryOperator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ public function insertsParentheses(): bool
106106
{
107107
return $this->insertParentheses;
108108
}
109-
}
109+
}

src/Clauses/CallProcedureClause.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24-
use InvalidArgumentException;
24+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2525
use WikibaseSolutions\CypherDSL\Types\AnyType;
2626
use WikibaseSolutions\CypherDSL\Variable;
2727

@@ -32,6 +32,8 @@
3232
*/
3333
class CallProcedureClause extends Clause
3434
{
35+
use ErrorTrait;
36+
3537
/**
3638
* @var string|null The procedure to call
3739
*/
@@ -104,9 +106,7 @@ public function getArguments(): array
104106
public function withArguments(array $arguments): self
105107
{
106108
foreach ($arguments as $argument) {
107-
if (!($argument instanceof AnyType)) {
108-
throw new InvalidArgumentException("\$arguments should only consist of AnyType objects");
109-
}
109+
$this->assertClass('argument', AnyType::class, $argument);
110110
}
111111

112112
$this->arguments = $arguments;
@@ -137,9 +137,7 @@ public function addArgument(AnyType $argument): self
137137
public function yields(array $variables): self
138138
{
139139
foreach ($variables as $variable) {
140-
if (!($variable instanceof Variable)) {
141-
throw new InvalidArgumentException("\$variables should only consist of Variable objects");
142-
}
140+
$this->assertClass('variable', Variable::class, $variable);
143141
}
144142

145143
$this->yieldVariables = $variables;
@@ -166,18 +164,18 @@ protected function getSubject(): string
166164

167165
$arguments = implode(
168166
", ",
169-
array_map(fn(AnyType $pattern): string => $pattern->toQuery(), $this->arguments)
167+
array_map(fn (AnyType $pattern): string => $pattern->toQuery(), $this->arguments)
170168
);
171169

172170
if (count($this->yieldVariables) > 0) {
173171
$yieldParameters = implode(
174172
", ",
175-
array_map(fn(Variable $variable): string => $variable->toQuery(), $this->yieldVariables)
173+
array_map(fn (Variable $variable): string => $variable->toQuery(), $this->yieldVariables)
176174
);
177175

178176
return sprintf("%s(%s) YIELD %s", $this->procedure, $arguments, $yieldParameters);
179177
} else {
180178
return sprintf("%s(%s)", $this->procedure, $arguments);
181179
}
182180
}
183-
}
181+
}

src/Clauses/Clause.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ public function canBeEmpty(): bool
6868
* @return string
6969
*/
7070
abstract protected function getClause(): string;
71-
}
71+
}

src/Clauses/CreateClause.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24+
use WikibaseSolutions\CypherDSL\Assignment;
25+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2426
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2527

2628
/**
@@ -30,19 +32,23 @@
3032
*/
3133
class CreateClause extends Clause
3234
{
35+
use ErrorTrait;
36+
3337
/**
34-
* @var StructuralType[] The patterns to create
38+
* @var StructuralType[]|Assignment[] The patterns to create
3539
*/
3640
private array $patterns = [];
3741

3842
/**
3943
* Add a pattern to create.
4044
*
41-
* @param StructuralType $pattern The pattern to create
45+
* @param StructuralType|Assignment $pattern The pattern to create
4246
* @return CreateClause
4347
*/
44-
public function addPattern(StructuralType $pattern): self
48+
public function addPattern($pattern): self
4549
{
50+
$this->assertClass('pattern', [StructuralType::class, Assignment::class], $pattern);
51+
4652
$this->patterns[] = $pattern;
4753

4854
return $this;
@@ -73,7 +79,7 @@ protected function getSubject(): string
7379
{
7480
return implode(
7581
", ",
76-
array_map(fn(StructuralType $pattern): string => $pattern->toQuery(), $this->patterns)
82+
array_map(fn ($pattern): string => $pattern->toQuery(), $this->patterns)
7783
);
7884
}
79-
}
85+
}

src/Clauses/DeleteClause.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function getSubject(): string
111111
{
112112
return implode(
113113
", ",
114-
array_map(fn(NodeType $node) => $node->toQuery(), $this->nodes)
114+
array_map(fn (NodeType $node) => $node->toQuery(), $this->nodes)
115115
);
116116
}
117-
}
117+
}

src/Clauses/LimitClause.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ protected function getSubject(): string
7979

8080
return "";
8181
}
82-
}
82+
}

src/Clauses/MatchClause.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24+
use WikibaseSolutions\CypherDSL\Assignment;
25+
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2426
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2527

2628
/**
@@ -30,8 +32,10 @@
3032
*/
3133
class MatchClause extends Clause
3234
{
35+
use ErrorTrait;
36+
3337
/**
34-
* @var StructuralType[] List of patterns
38+
* @var StructuralType[]|Assignment[] List of patterns
3539
*/
3640
private array $patterns = [];
3741

@@ -48,11 +52,13 @@ public function getPatterns(): array
4852
/**
4953
* Add a pattern to the match clause.
5054
*
51-
* @param StructuralType $pattern
55+
* @param StructuralType|Assignment $pattern
5256
* @return MatchClause
5357
*/
54-
public function addPattern(StructuralType $pattern): self
58+
public function addPattern($pattern): self
5559
{
60+
$this->assertClass('pattern', [StructuralType::class, Assignment::class], $pattern);
61+
5662
$this->patterns[] = $pattern;
5763

5864
return $this;
@@ -73,7 +79,7 @@ protected function getSubject(): string
7379
{
7480
return implode(
7581
", ",
76-
array_map(fn(StructuralType $pattern): string => $pattern->toQuery(), $this->patterns)
82+
array_map(fn ($pattern): string => $pattern->toQuery(), $this->patterns)
7783
);
7884
}
79-
}
85+
}

0 commit comments

Comments
 (0)