Skip to content

Commit 9f67f5d

Browse files
Merge pull request #100 from neo4j-php/89-use-php-80-union-types
Upgrade to PHP 8.1
2 parents ac5a3f2 + 69fad51 commit 9f67f5d

94 files changed

Lines changed: 1539 additions & 2487 deletions

File tree

Some content is hidden

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

.github/CONTRIBUTING.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Feel free to propose a new feature by [opening an issue for it](https://github.c
3737

3838
1. Fork the repository.
3939
1. Create a new branch.
40-
1. If you are **implementing new functionality**, create your branch from `development`.
40+
1. If you are **implementing new functionality**, create your branch from `main`.
4141
1. If you are **fixing a bug**, create your branch from the oldest [supported](https://github.com/neo4j-php/php-cypher-dsl/blob/main/LIFECYCLE.md) branch that is affected by the bug.
4242
1. Implement your change and add tests for it.
4343
1. Make sure the test suite passes.
@@ -50,18 +50,6 @@ Some things to keep in mind:
5050
* Keep backwards compatibility breaks to a minimum.
5151
* You are encouraged to [sign your commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with GPG.
5252

53-
## Branching model
54-
55-
The branching model used by this project is [gitflow](https://nvie.com/posts/a-successful-git-branching-model/), with the following changes/additions:
56-
57-
1. Feature branches must follow the naming convention `feature/*`.
58-
1. The name of a feature branch should reflect the feature added (e.g. `feature/support-indexing-operator` instead of `feature/feature-1`).
59-
1. Release branches must follow the naming convention `release/x.y`, where `x` and `y` are the major and minor version of the release respectively. A release branch should never be made for a patch.
60-
1. Hotfix branches must follow the naming convention `hotfix/x.y.z`, where `x`, `y` and `z` are the major, minor and patch version of the hot respectively.
61-
1. Hotfix branches must branch off from the oldest [supported](https://github.com/neo4j-php/php-cypher-dsl/blob/main/LIFECYCLE.md) branch that is affected by the bug.
62-
1. Right before a new **major** version is released, a *support* branch is created from `main`.
63-
1. Support branches must follow the naming convention `support/x.y`, where `x` and `y` are the major and minor version of the most recent release respectively.
64-
6553
## Coding guidelines
6654

6755
This project comes with a [configuration file](https://github.com/neo4j-php/php-cypher-dsl/blob/main/.php-cs-fixer.dist.php) for `php-cs-fixer` that you can use to format your code:
@@ -81,7 +69,7 @@ After making your changes and adding your tests, you can check whether the minim
8169
```
8270
$ XDEBUG_MODE=coverage php vendor/bin/phpunit --testsuite unit
8371
$ php vendor/bin/coverage-check coverage/clover.xml 90
84-
$ XDEBUG_MODE=coverage php vendor/bin/infection --min-msi=80
72+
$ XDEBUG_MODE=coverage php vendor/bin/infection --min-msi=85
8573
```
8674

8775
## Running test suites

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
php-version: [ "7.4", "8.0", "8.1", "8.2" ]
17+
php-version: [ "8.1", "8.2", "8.3", "8.4", "8.5" ]
1818

1919
env:
2020
COMPOSER_VERSION: 2
2121
COVERAGE_DRIVER: xdebug
2222
MINIMUM_COVERAGE_PERCENTAGE: 90
23-
MINIMUM_MSI_PERCENTAGE: 80
23+
MINIMUM_MSI_PERCENTAGE: 85
2424

2525
steps:
2626
- name: Checkout repository

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ file. A changelog has been kept from version 5.0.0 onwards.
66
The format is based on [Keep a Changelog], and this project adheres to
77
[Semantic Versioning].
88

9+
## 7.0.0 - T.B.D.
10+
11+
### Changed
12+
13+
- Changed the minimum required PHP version to 8.1.
14+
- Changed the signature of many functions to use PHP 8 union types.
15+
- Changed the `Relationship::DIR_*` to the `Direction` enum.
16+
17+
### Removed
18+
19+
- Removed unnecessary dependency for the `openssl` PHP library.
20+
- Removed `ErrorTrait` in favor of PHP 8.0 union types.
21+
- Removed `CastTrait` in favor of the static functions in `CastUtils`.
22+
- Removed `NameGenerationTrait` in favor of the static functions in `NameUtils`.
23+
- Removed `EscapeTrait` in favor of the static functions in `NameUtils`.
24+
- Removed `Relationship::DIR_UNI`, `Relationship::DIR_LEFT` and `Relationship::DIR_RIGHT` constants
25+
in favor of the `Direction` enum.
26+
927
## 6.0.0 - 2023-09-19
1028

1129
### Changed

LIFECYCLE.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ loss and/or corruption.
1616

1717
## Supported versions
1818

19-
| Major version | PHP version | Initial release | End of bugfix support |
20-
|------------------|-------------|-----------------|-----------------------|
21-
| php-cypher-dsl 5 | >=7.4 | Jan 9th, 2023 | Mar 19th, 2024 |
22-
| php-cypher-dsl 6 | >=7.4 | Sep 19th, 2023 | To be determined |
19+
| Major version | PHP version | Initial release | End of bugfix support |
20+
|------------------|-------------|-------------------|-----------------------|
21+
| php-cypher-dsl 5 | >=7.4 | Jan 9th, 2023 | Mar 19th, 2024 |
22+
| php-cypher-dsl 6 | >=7.4 | Sep 19th, 2023 | To be determined |
23+
| php-cypher-dsl 7 | >=8.1 | To be determined | To be determined |

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
# php-cypher-dsl
22

3-
The `php-cypher-dsl` library provides a way to construct advanced Cypher
4-
queries in an object-oriented and type-safe manner.
3+
The `php-cypher-dsl` library provides a way to construct Cypher queries in a type-safe manner.
54

65
## Documentation
76

8-
[The documentation can be found on the wiki
9-
here.](https://github.com/WikibaseSolutions/php-cypher-dsl/wiki)
7+
[The documentation can be found on the wiki here.](https://github.com/WikibaseSolutions/php-cypher-dsl/wiki)
108

119
## Installation
1210

1311
### Requirements
1412

15-
`php-cypher-dsl` requires PHP 7.4 or greater; using the latest version of PHP
16-
is highly recommended.
13+
`php-cypher-dsl` requires PHP 8.1 or greater; using the latest version of PHP is highly recommended.
1714

1815
### Installation through Composer
1916

20-
You can install `php-cypher-dsl` through composer by running the following
21-
command:
17+
You can install `php-cypher-dsl` through Composer by running the following command:
2218

2319
```
2420
composer require "wikibase-solutions/php-cypher-dsl"
@@ -30,8 +26,7 @@ Please refer to [CONTRIBUTING.md](https://github.com/neo4j-php/php-cypher-dsl/bl
3026

3127
## Example
3228

33-
To construct a query to find all of Tom Hanks' co-actors, you can use the
34-
following code:
29+
To construct a query to find all of Tom Hanks' co-actors, you can use the following code:
3530

3631
```php
3732
use function WikibaseSolutions\CypherDSL\node;
@@ -41,7 +36,13 @@ $tom = node("Person")->withProperties(["name" => "Tom Hanks"]);
4136
$coActors = node();
4237

4338
$statement = query()
44-
->match($tom->relationshipTo(Query::node(), "ACTED_IN")->relationshipFrom($coActors, "ACTED_IN"))
39+
->match($tom->relationshipTo(node(), "ACTED_IN")->relationshipFrom($coActors, "ACTED_IN"))
4540
->returning($coActors->property("name"))
4641
->build();
4742
```
43+
44+
This produces the following Cypher query (where `$1` is a random variable name):
45+
46+
```
47+
MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->()<-[:ACTED_IN]-($1) RETURN $1.name
48+
```

composer.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wikibase-solutions/php-cypher-dsl",
3-
"description": "A query builder for the Cypher query language written in PHP",
3+
"description": "A query builder for the Cypher query language",
44
"type": "library",
55
"keywords": [
66
"neo4j",
@@ -46,18 +46,15 @@
4646
"source": "https://github.com/WikibaseSolutions/php-cypher-dsl"
4747
},
4848
"require": {
49-
"php": ">=7.4",
50-
"ext-ctype": "*",
51-
"ext-openssl": "*",
52-
"symfony/polyfill-php80": "^1.25",
53-
"symfony/polyfill-php81": "^1.25"
49+
"php": ">=8.1",
50+
"ext-ctype": "*"
5451
},
5552
"require-dev": {
56-
"phpunit/phpunit": "~9.0",
57-
"infection/infection": "^0.25.5",
53+
"phpunit/phpunit": "^10.0",
54+
"infection/infection": "^0.29",
5855
"friendsofphp/php-cs-fixer": "^3.0",
5956
"rregeer/phpunit-coverage-check": "^0.3.1",
60-
"phpstan/phpstan": "^1.8"
57+
"phpstan/phpstan": "^2.0"
6158
},
6259
"autoload": {
6360
"files": [

phpstan.neon.dist

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
paths:
33
- src
4-
level: 7
5-
treatPhpDocTypesAsCertain: false
4+
level: 9
5+
treatPhpDocTypesAsCertain: false
6+
ignoreErrors:
7+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
8+
- "#Function [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
9+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type iterable#"
10+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ return type has no value type specified in iterable type array#"

phpunit.xml.dist

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" verbose="true"
2+
<phpunit colors="true"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
displayDetailsOnTestsThatTriggerDeprecations="true"
6+
displayDetailsOnTestsThatTriggerErrors="true"
7+
displayDetailsOnTestsThatTriggerNotices="true"
8+
displayDetailsOnTestsThatTriggerWarnings="true"
9+
displayDetailsOnPhpunitDeprecations="true"
510
bootstrap="vendor/autoload.php"
611
>
712
<testsuites>
@@ -15,16 +20,18 @@
1520
<directory>tests/integration</directory>
1621
</testsuite>
1722
</testsuites>
18-
<coverage processUncoveredFiles="true" cacheDirectory="coverage/cache" pathCoverage="true">
19-
<report>
20-
<clover outputFile="coverage/clover.xml" />
21-
<html outputDirectory="coverage/" />
22-
</report>
23+
<source>
2324
<include>
2425
<directory suffix=".php">src</directory>
2526
</include>
2627
<exclude>
2728
<file>src/functions.php</file>
2829
</exclude>
30+
</source>
31+
<coverage cacheDirectory="coverage/cache" pathCoverage="true">
32+
<report>
33+
<clover outputFile="coverage/clover.xml" />
34+
<html outputDirectory="coverage/" />
35+
</report>
2936
</coverage>
3037
</phpunit>

src/Clauses/CallClause.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use WikibaseSolutions\CypherDSL\Expressions\Variable;
1313
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
1414
use WikibaseSolutions\CypherDSL\Query;
15-
use WikibaseSolutions\CypherDSL\Traits\CastTrait;
16-
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
15+
use WikibaseSolutions\CypherDSL\Utils\CastUtils;
1716

1817
/**
1918
* This class represents a CALL {} (subquery) clause. The CALL {} clause evaluates a subquery that returns
@@ -26,9 +25,6 @@
2625
*/
2726
final class CallClause extends Clause
2827
{
29-
use CastTrait;
30-
use ErrorTrait;
31-
3228
/**
3329
* @var null|Query The sub-query to call, or NULL if no sub-query has been set yet
3430
*/
@@ -56,18 +52,14 @@ public function withSubQuery(Query $subQuery): self
5652
/**
5753
* Add one or more variables to include in the WITH clause.
5854
*
59-
* @param Pattern|string|Variable ...$variables
60-
*
61-
* @return $this
62-
*
6355
* @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-correlated-importing
6456
*/
65-
public function addWithVariable(...$variables): self
57+
public function addWithVariable(Pattern|Variable|string ...$variables): self
6658
{
6759
$res = [];
6860

6961
foreach ($variables as $variable) {
70-
$res[] = self::toVariable($variable);
62+
$res[] = CastUtils::toVariable($variable);
7163
}
7264

7365
$this->withVariables = array_merge($this->withVariables, $res);

src/Clauses/CallProcedureClause.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use WikibaseSolutions\CypherDSL\Expressions\Procedures\Procedure;
1313
use WikibaseSolutions\CypherDSL\Expressions\Variable;
1414
use WikibaseSolutions\CypherDSL\Syntax\Alias;
15-
use WikibaseSolutions\CypherDSL\Traits\CastTrait;
15+
use WikibaseSolutions\CypherDSL\Utils\CastUtils;
1616

1717
/**
1818
* This class represents a CALL procedure clause.
@@ -25,24 +25,20 @@
2525
*/
2626
final class CallProcedureClause extends Clause
2727
{
28-
use CastTrait;
29-
3028
/**
3129
* @var null|Procedure The procedure to call
3230
*/
3331
private ?Procedure $procedure = null;
3432

3533
/**
36-
* @var Alias[]|Variable[]|(Alias|Variable)[] The result fields that are yielded
34+
* @var Alias[]|(Alias|Variable)[]|Variable[] The result fields that are yielded
3735
*/
3836
private array $yields = [];
3937

4038
/**
4139
* Sets the procedure to call.
4240
*
4341
* @param Procedure $procedure The procedure to call
44-
*
45-
* @return $this
4642
*/
4743
public function setProcedure(Procedure $procedure): self
4844
{
@@ -55,15 +51,13 @@ public function setProcedure(Procedure $procedure): self
5551
* Adds a variable to yield.
5652
*
5753
* @param Alias|string|Variable $yields The variable to yield
58-
*
59-
* @return $this
6054
*/
6155
public function addYield(...$yields): self
6256
{
6357
$res = [];
6458

6559
foreach ($yields as $yield) {
66-
$res[] = $yield instanceof Alias ? $yield : self::toName($yield);
60+
$res[] = $yield instanceof Alias ? $yield : CastUtils::toName($yield);
6761
}
6862

6963
$this->yields = array_merge($this->yields, $res);
@@ -73,8 +67,6 @@ public function addYield(...$yields): self
7367

7468
/**
7569
* Returns the procedure to call.
76-
*
77-
* @return Procedure
7870
*/
7971
public function getProcedure(): ?Procedure
8072
{
@@ -84,7 +76,7 @@ public function getProcedure(): ?Procedure
8476
/**
8577
* Returns the variables to yield.
8678
*
87-
* @return Alias[]|Variable[]|(Alias|Variable)[]
79+
* @return (Alias|Variable)[]
8880
*/
8981
public function getYields(): array
9082
{

0 commit comments

Comments
 (0)