Skip to content

Commit d300b5d

Browse files
authored
Merge branch 'main' into nullables
2 parents c056d76 + 79a57b6 commit d300b5d

Some content is hidden

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

62 files changed

+801
-299
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ jobs:
5555
- name: Install dependencies
5656
run: composer update --working-dir ${{ env.INSTALL_PATH }}
5757

58+
- name: Run php-cs-fixer
59+
run: |
60+
composer php-cs-fixer --working-dir ${{ env.INSTALL_PATH }} -- --dry-run ./src
61+
composer php-cs-fixer --working-dir ${{ env.INSTALL_PATH }} -- --dry-run ./tests
62+
5863
- name: Run unit tests
5964
run: composer test --working-dir ${{ env.INSTALL_PATH }}
6065

6166
- name: Run mutation tests
62-
run: composer infect --working-dir ${{ env.INSTALL_PATH }}
67+
run: composer infect --working-dir ${{ env.INSTALL_PATH }}

composer.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
"homepage": "https://wikibase-solutions.com/author/marijn",
2121
"role": "Developer"
2222
},
23+
{
24+
"name": "Wout Gevaert",
25+
"email": "[email protected]",
26+
"homepage": "https://wikibase-solutions.com/author/wout",
27+
"role": "Developer"
28+
},
29+
{
30+
"name": "Ghlen Nagels",
31+
"email": "[email protected]",
32+
"homepage": "https://nagels.tech",
33+
"role": "Developer"
34+
},
2335
{
2436
"name": "Lars Akkermans",
2537
"email": "[email protected]",
@@ -40,7 +52,8 @@
4052
},
4153
"require-dev": {
4254
"phpunit/phpunit": "~9.0",
43-
"infection/infection": "^0.25.5"
55+
"infection/infection": "^0.25.5",
56+
"friendsofphp/php-cs-fixer": "^3.0"
4457
},
4558
"autoload": {
4659
"psr-4": {
@@ -54,7 +67,9 @@
5467
},
5568
"scripts": {
5669
"test": "phpunit tests/",
57-
"infect": "XDEBUG_MODE=coverage infection --show-mutations"
70+
"infect": "XDEBUG_MODE=coverage infection --show-mutations",
71+
"php-cs-fixer":
72+
"php-cs-fixer fix --verbose --rules=@PSR12,align_multiline_comment,array_indentation,blank_line_before_statement,no_unused_imports,no_useless_else,no_useless_return,ordered_imports,phpdoc_scalar,return_assignment,simplified_if_return,trailing_comma_in_multiline"
5873
},
5974
"minimum-stability": "stable",
6075
"prefer-stable": true

src/Alias.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
namespace WikibaseSolutions\CypherDSL;
2323

24-
use WikibaseSolutions\CypherDSL\Types\AnyType;
2524
use function sprintf;
25+
use WikibaseSolutions\CypherDSL\Types\AnyType;
2626

2727
/**
2828
* Represents aliasing an expression or variable.

src/Clauses/CallClause.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace WikibaseSolutions\CypherDSL\Clauses;
4+
5+
use WikibaseSolutions\CypherDSL\Query;
6+
7+
/**
8+
* This class represents a CALL clause.
9+
*
10+
* @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/
11+
*/
12+
class CallClause extends Clause
13+
{
14+
/**
15+
* @var Query The query to call.
16+
*/
17+
private Query $subQuery;
18+
19+
/**
20+
* @param Query $subQuery The query to call.
21+
*/
22+
public function __construct(Query $subQuery)
23+
{
24+
$this->subQuery = $subQuery;
25+
}
26+
27+
/**
28+
* Returns the query that is being called.
29+
*
30+
* @return Query
31+
*/
32+
public function getSubQuery(): Query
33+
{
34+
return $this->subQuery;
35+
}
36+
37+
public function toQuery(): string
38+
{
39+
$subQuery = trim($this->subQuery->toQuery());
40+
41+
if ($subQuery === '') {
42+
return '';
43+
}
44+
45+
return sprintf('CALL { %s }', $subQuery);
46+
}
47+
48+
/**
49+
* @inheritDoc
50+
*/
51+
protected function getSubject(): string
52+
{
53+
return '{ ' . $this->subQuery->toQuery() . ' }';
54+
}
55+
56+
/**
57+
* @inheritDoc
58+
*/
59+
protected function getClause(): string
60+
{
61+
return 'CALL';
62+
}
63+
}

src/Clauses/CallProcedureClause.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ protected function getSubject(): string
174174
);
175175

176176
return sprintf("%s(%s) YIELD %s", $this->procedure, $arguments, $yieldParameters);
177-
} else {
178-
return sprintf("%s(%s)", $this->procedure, $arguments);
179177
}
178+
179+
return sprintf("%s(%s)", $this->procedure, $arguments);
180180
}
181181
}

src/Clauses/CreateClause.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents a CREATE clause.
@@ -34,18 +35,19 @@ class CreateClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] The patterns to create
38+
* @var (PathType|NodeType)[] The patterns to create
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Add a pattern to create.
4344
*
44-
* @param StructuralType $pattern The pattern to create
45+
* @param PathType|NodeType $pattern The pattern to create
4546
* @return CreateClause
4647
*/
47-
public function addPattern(StructuralType $pattern): self
48+
public function addPattern($pattern): self
4849
{
50+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
4951
$this->patterns[] = $pattern;
5052

5153
return $this;
@@ -54,7 +56,7 @@ public function addPattern(StructuralType $pattern): self
5456
/**
5557
* Returns the patterns of the create clause.
5658
*
57-
* @return StructuralType[]
59+
* @return (PathType|NodeType)[]
5860
*/
5961
public function getPatterns(): array
6062
{

src/Clauses/DeleteClause.php

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

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24-
use WikibaseSolutions\CypherDSL\Types\AnyType;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
24+
use WikibaseSolutions\CypherDSL\Variable;
2625

2726
/**
2827
* This class represents a DELETE clause.
@@ -39,11 +38,11 @@ class DeleteClause extends Clause
3938
private bool $detach = false;
4039

4140
/**
42-
* The nodes that needs to be deleted.
41+
* The variables that needs to be deleted.
4342
*
44-
* @var AnyType[] $nodes
43+
* @var Variable[] $variables
4544
*/
46-
private array $nodes = [];
45+
private array $variables = [];
4746

4847
/**
4948
* Sets the clause to DETACH DELETE. Without DETACH DELETE, all relationships need to be explicitly
@@ -60,14 +59,14 @@ public function setDetach(bool $detach = true): self
6059
}
6160

6261
/**
63-
* Add the node to be deleted. The expression must return a node when evaluated.
62+
* Add the variable to be deleted. The expression must return a node when evaluated.
6463
*
65-
* @param NodeType $node Expression that returns the node to be deleted
64+
* @param Variable $variable The name of the object that should be deleted
6665
* @return DeleteClause
6766
*/
68-
public function addNode(NodeType $node): self
67+
public function addVariable(Variable $variable): self
6968
{
70-
$this->nodes[] = $node;
69+
$this->variables[] = $variable;
7170

7271
return $this;
7372
}
@@ -83,13 +82,13 @@ public function detachesDeletion(): bool
8382
}
8483

8584
/**
86-
* Returns the nodes to delete.
85+
* Returns the variables to delete.
8786
*
88-
* @return AnyType[]
87+
* @return Variable[]
8988
*/
90-
public function getNodes(): array
89+
public function getVariables(): array
9190
{
92-
return $this->nodes;
91+
return $this->variables;
9392
}
9493

9594
/**
@@ -111,7 +110,7 @@ protected function getSubject(): string
111110
{
112111
return implode(
113112
", ",
114-
array_map(fn (NodeType $node) => $node->toQuery(), $this->nodes)
113+
array_map(fn (Variable $variable) => $variable->toQuery(), $this->variables)
115114
);
116115
}
117116
}

src/Clauses/MatchClause.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents a MATCH clause.
@@ -34,14 +35,14 @@ class MatchClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] List of patterns
38+
* @var (PathType|NodeType)[] List of patterns
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Returns the patterns to match.
4344
*
44-
* @return StructuralType[]
45+
* @return (PathType|NodeType)[]
4546
*/
4647
public function getPatterns(): array
4748
{
@@ -51,11 +52,12 @@ public function getPatterns(): array
5152
/**
5253
* Add a pattern to the match clause.
5354
*
54-
* @param StructuralType $pattern
55+
* @param PathType|NodeType $pattern
5556
* @return MatchClause
5657
*/
57-
public function addPattern(StructuralType $pattern): self
58+
public function addPattern($pattern): self
5859
{
60+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
5961
$this->patterns[] = $pattern;
6062

6163
return $this;

src/Clauses/MergeClause.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2527
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2628

2729
/**
@@ -34,7 +36,7 @@ class MergeClause extends Clause
3436
use ErrorTrait;
3537

3638
/**
37-
* @var StructuralType|null $pattern The pattern to merge
39+
* @var PathType|NodeType|null $pattern The pattern to merge
3840
*/
3941
private ?StructuralType $pattern = null;
4042

@@ -71,7 +73,7 @@ public function getOnMatchClause(): ?Clause
7173
/**
7274
* Returns the pattern to MERGE.
7375
*
74-
* @return StructuralType|null
76+
* @return PathType|NodeType|null
7577
*/
7678
public function getPattern(): ?StructuralType
7779
{
@@ -81,11 +83,12 @@ public function getPattern(): ?StructuralType
8183
/**
8284
* Sets the pattern to merge.
8385
*
84-
* @param StructuralType $pattern The pattern to merge
86+
* @param PathType|NodeType $pattern The pattern to merge
8587
* @return MergeClause
8688
*/
87-
public function setPattern(StructuralType $pattern): self
89+
public function setPattern($pattern): self
8890
{
91+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
8992
$this->pattern = $pattern;
9093

9194
return $this;

src/Clauses/OptionalMatchClause.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents an OPTIONAL MATCH clause.
@@ -34,14 +35,14 @@ class OptionalMatchClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] List of patterns
38+
* @var (PathType|NodeType)[] List of patterns
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Returns the patterns to optionally match.
4344
*
44-
* @return StructuralType[]
45+
* @return (PathType|NodeType)[]
4546
*/
4647
public function getPatterns(): array
4748
{
@@ -51,11 +52,12 @@ public function getPatterns(): array
5152
/**
5253
* Add a pattern to the optional match clause.
5354
*
54-
* @param StructuralType $pattern
55+
* @param PathType|NodeType $pattern
5556
* @return OptionalMatchClause
5657
*/
57-
public function addPattern(StructuralType $pattern): self
58+
public function addPattern($pattern): self
5859
{
60+
$this->assertClass('pattern', [NodeType::class, PathType::class], $pattern);
5961
$this->patterns[] = $pattern;
6062

6163
return $this;

0 commit comments

Comments
 (0)