Skip to content

Commit 47d972e

Browse files
authored
Merge pull request #247 from neo4j-php/feat/remove-formatter
feat!: Remove formatter feat!: Simplify Cypher list and Map
2 parents 6c578a0 + be6a56c commit 47d972e

File tree

103 files changed

+2071
-2484
lines changed

Some content is hidden

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

103 files changed

+2071
-2484
lines changed

.github/workflows/static-analysis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,33 @@ on:
77
pull_request:
88
branches:
99
- main
10-
1110
jobs:
1211
php-cs-fixer:
1312
name: "Lint & Analyse"
1413
runs-on: ubuntu-latest
1514
steps:
1615
- uses: actions/checkout@v2
16+
17+
# Setup the correct PHP version globally
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.3.16'
22+
1723
- name: Cache Composer dependencies
1824
uses: actions/cache@v2
1925
with:
2026
path: /tmp/composer-cache
2127
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
28+
2229
- uses: php-actions/composer@v6
2330
with:
2431
progress: yes
25-
php_version: 8.3
32+
php_version: 8.3.16
2633
version: 2
34+
2735
- name: "PHP-CS-Fixer"
2836
run: vendor/bin/php-cs-fixer fix --dry-run
37+
2938
- name: "PSalm"
3039
run: vendor/bin/psalm --show-info=true

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: "Running Unit Tests"
1515
strategy:
1616
matrix:
17-
php: ['8.1', '8.2', '8.3']
17+
php: ['8.1.31', '8.2.27', '8.3.16']
1818

1919
steps:
2020
- uses: actions/checkout@v2

.php-cs-fixer.dist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
MultilineCommentOpeningClosingAloneFixer::name() => true,
6464
MultilinePromotedPropertiesFixer::name() => true,
6565
PhpUnitAssertArgumentsOrderFixer::name() => true,
66-
PhpdocNoSuperfluousParamFixer::name() => true,
6766
PhpdocParamOrderFixer::name() => true,
6867
StringableInterfaceFixer::name() => true,
6968
])

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,21 +308,16 @@ composer require nyholm/psr7 nyholm/psr7-server kriswallsmith/buzz
308308

309309
## Result formats/hydration
310310

311-
In order to make the results of the bolt protocol and the http uniform, the driver provides result formatters (aka hydrators). The client is configurable with these formatters. You can even implement your own.
311+
In order to make the results of the bolt protocol and the http uniform, the driver provides and summarizes the results.
312312

313-
The default formatter is the `\Laudis\Neo4j\Formatters\OGMFormatter`, which is explained extensively in [the result format section](#accessing-the-results).
313+
The default formatter is the `\Laudis\Neo4j\Formatters\SummarizedResultFormatter`, which is explained extensively in [the result format section](#accessing-the-results).
314314

315-
The driver provides three formatters by default, which are all found in the Formatter namespace:
316-
- `\Laudis\Neo4j\Formatter\BasicFormatter` which erases all the Cypher types and simply returns every value in the resulting map as a [scalar](https://www.php.net/manual/en/function.is-scalar.php), null or array value.
317-
- `\Laudis\Neo4j\Formatter\OGMFormatter` which maps the cypher types to php types as explained [here](#accessing-the-results).
318-
- `\Laudis\Neo4j\Formatter\SummarizedResultFormatter` which decorates any formatter and adds an extensive result summary.
315+
`\Laudis\Neo4j\Formatter\SummarizedResultFormatter` adds an extensive result summary.
319316

320317
The client builder provides an easy way to change the formatter:
321318

322319
```php
323-
$client = \Laudis\Neo4j\ClientBuilder::create()
324-
->withFormatter(\Laudis\Neo4j\Formatter\SummarizedResultFormatter::create())
325-
->build();
320+
$client = \Laudis\Neo4j\ClientBuilder::create()->build();
326321

327322
/**
328323
* The client will now return a result, decorated with a summary.
@@ -339,8 +334,6 @@ $summary = $summarisedResult->getSummary();
339334
$result = $summarisedResult->getResult();
340335
```
341336

342-
In order to use a custom formatter, implement the `Laudis\Neo4j\Contracts\FormatterInterface` and provide it when using the client builder.
343-
344337
## Concepts
345338

346339
The driver API described [here](https://neo4j.com/docs/driver-manual/current/) is the main target of the driver. Because of this, the client is nothing more than a driver manager. The driver creates sessions. A session runs queries through a transaction.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"nyholm/psr7": "^1.3",
4949
"nyholm/psr7-server": "^1.0",
5050
"kriswallsmith/buzz": "^1.2",
51-
"vimeo/psalm": "^5.0",
52-
"friendsofphp/php-cs-fixer": "3.15.0",
53-
"psalm/plugin-phpunit": "^0.18",
51+
"vimeo/psalm": "^6.5",
52+
"friendsofphp/php-cs-fixer": "3.68.5",
53+
"psalm/plugin-phpunit": "^0.19",
5454
"monolog/monolog": "^2.2",
5555
"symfony/uid": "^5.0",
5656
"symfony/var-dumper": "^5.0",

psalm.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@
3030
<directory name="src"/>
3131
</errorLevel>
3232
</UnusedForeachValue>
33-
<DeprecatedClass>
34-
<errorLevel type="suppress">
35-
<directory name="tests"/>
36-
<directory name="src"/>
37-
</errorLevel>
38-
</DeprecatedClass>
39-
<DeprecatedInterface>
40-
<errorLevel type="suppress">
41-
<directory name="tests"/>
42-
<directory name="src"/>
43-
</errorLevel>
44-
</DeprecatedInterface>
4533
<MissingConstructor>
4634
<errorLevel type="suppress">
4735
<directory name="tests"/>

src/Authentication/BasicAuth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function __construct(
3838
private readonly string $username,
3939
private readonly string $password,
4040
private readonly ?Neo4jLogger $logger,
41-
) {}
41+
) {
42+
}
4243

4344
/**
4445
* @throws Exception

src/Authentication/KerberosAuth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ final class KerberosAuth implements AuthenticateInterface
4040
public function __construct(
4141
private readonly string $token,
4242
private readonly ?Neo4jLogger $logger,
43-
) {}
43+
) {
44+
}
4445

4546
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
4647
{
4748
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using KerberosAuth');
49+
4850
/**
4951
* @psalm-suppress ImpureMethodCall Request is a pure object:
5052
*

src/Authentication/NoAuth.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ final class NoAuth implements AuthenticateInterface
3838
* @pure
3939
*/
4040
public function __construct(
41-
private readonly ?Neo4jLogger $logger
42-
) {}
41+
private readonly ?Neo4jLogger $logger,
42+
) {
43+
}
4344

4445
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
4546
{
4647
$this->logger?->log(LogLevel::DEBUG, 'Authentication disabled');
48+
4749
/**
4850
* @psalm-suppress ImpureMethodCall Request is a pure object:
4951
*

src/Authentication/OpenIDConnectAuth.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ final class OpenIDConnectAuth implements AuthenticateInterface
3636
*/
3737
public function __construct(
3838
private readonly string $token,
39-
private readonly ?Neo4jLogger $logger
40-
) {}
39+
private readonly ?Neo4jLogger $logger,
40+
) {
41+
}
4142

4243
public function authenticateHttp(RequestInterface $request, UriInterface $uri, string $userAgent): RequestInterface
4344
{
4445
$this->logger?->log(LogLevel::DEBUG, 'Authenticating using OpenIDConnectAuth');
46+
4547
/**
4648
* @psalm-suppress ImpureMethodCall Request is a pure object:
4749
*

src/Basic/Client.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
use Laudis\Neo4j\Databags\SummarizedResult;
1919
use Laudis\Neo4j\Databags\TransactionConfiguration;
2020
use Laudis\Neo4j\Types\CypherList;
21-
use Laudis\Neo4j\Types\CypherMap;
2221

23-
/**
24-
* @implements ClientInterface<SummarizedResult<CypherMap>>
25-
*/
2622
final class Client implements ClientInterface
2723
{
28-
/**
29-
* @param ClientInterface<SummarizedResult<CypherMap>> $client
30-
*/
3124
public function __construct(
32-
private readonly ClientInterface $client
33-
) {}
25+
private readonly ClientInterface $client,
26+
) {
27+
}
3428

3529
public function run(string $statement, iterable $parameters = [], ?string $alias = null): SummarizedResult
3630
{

src/Basic/Driver.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,19 @@
1717
use Laudis\Neo4j\Contracts\DriverInterface;
1818
use Laudis\Neo4j\Databags\DriverConfiguration;
1919
use Laudis\Neo4j\Databags\SessionConfiguration;
20-
use Laudis\Neo4j\Databags\SummarizedResult;
2120
use Laudis\Neo4j\DriverFactory;
2221
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
23-
use Laudis\Neo4j\Types\CypherMap;
2422
use Psr\Http\Message\UriInterface;
2523

26-
/**
27-
* @implements DriverInterface<SummarizedResult<CypherMap>>
28-
*/
2924
final class Driver implements DriverInterface
3025
{
3126
/**
32-
* @param DriverInterface<SummarizedResult<CypherMap>> $driver
33-
*
3427
* @psalm-external-mutation-free
3528
*/
3629
public function __construct(
37-
private readonly DriverInterface $driver
38-
) {}
30+
private readonly DriverInterface $driver,
31+
) {
32+
}
3933

4034
/**
4135
* @psalm-mutation-free
@@ -52,7 +46,6 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
5246

5347
public static function create(string|UriInterface $uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
5448
{
55-
/** @var DriverInterface<SummarizedResult<CypherMap>> */
5649
$driver = DriverFactory::create($uri, $configuration, $authenticate, SummarizedResultFormatter::create());
5750

5851
return new self($driver);

src/Basic/Session.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,31 @@
1919
use Laudis\Neo4j\Databags\SummarizedResult;
2020
use Laudis\Neo4j\Databags\TransactionConfiguration;
2121
use Laudis\Neo4j\Types\CypherList;
22-
use Laudis\Neo4j\Types\CypherMap;
2322

24-
/**
25-
* @implements SessionInterface<SummarizedResult<CypherMap>>
26-
*/
2723
final class Session implements SessionInterface
2824
{
29-
/**
30-
* @param SessionInterface<SummarizedResult<CypherMap>> $session
31-
*/
3225
public function __construct(
33-
private readonly SessionInterface $session
34-
) {}
26+
private readonly SessionInterface $session,
27+
) {
28+
}
3529

3630
/**
3731
* @param iterable<Statement> $statements
3832
*
39-
* @return CypherList<SummarizedResult<CypherMap>>
33+
* @return CypherList<SummarizedResult>
4034
*/
4135
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList
4236
{
4337
return $this->session->runStatements($statements, $config);
4438
}
4539

46-
/**
47-
* @return SummarizedResult<CypherMap>
48-
*/
4940
public function runStatement(Statement $statement, ?TransactionConfiguration $config = null): SummarizedResult
5041
{
5142
return $this->session->runStatement($statement, $config);
5243
}
5344

5445
/**
5546
* @param iterable<string, mixed> $parameters
56-
*
57-
* @return SummarizedResult<CypherMap>
5847
*/
5948
public function run(string $statement, iterable $parameters = [], ?TransactionConfiguration $config = null): SummarizedResult
6049
{

src/Basic/UnmanagedTransaction.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,22 @@
1717
use Laudis\Neo4j\Databags\Statement;
1818
use Laudis\Neo4j\Databags\SummarizedResult;
1919
use Laudis\Neo4j\Types\CypherList;
20-
use Laudis\Neo4j\Types\CypherMap;
2120

22-
/**
23-
* @implements UnmanagedTransactionInterface<SummarizedResult<CypherMap>>
24-
*/
2521
final class UnmanagedTransaction implements UnmanagedTransactionInterface
2622
{
27-
/**
28-
* @param UnmanagedTransactionInterface<SummarizedResult<CypherMap>> $tsx
29-
*/
3023
public function __construct(
31-
private readonly UnmanagedTransactionInterface $tsx
32-
) {}
24+
private readonly UnmanagedTransactionInterface $tsx,
25+
) {
26+
}
3327

3428
/**
3529
* @param iterable<string, mixed> $parameters
36-
*
37-
* @return SummarizedResult<CypherMap>
3830
*/
3931
public function run(string $statement, iterable $parameters = []): SummarizedResult
4032
{
4133
return $this->tsx->run($statement, $parameters);
4234
}
4335

44-
/**
45-
* @return SummarizedResult<CypherMap>
46-
*/
4736
public function runStatement(Statement $statement): SummarizedResult
4837
{
4938
return $this->tsx->runStatement($statement);
@@ -52,7 +41,7 @@ public function runStatement(Statement $statement): SummarizedResult
5241
/**
5342
* @param iterable<Statement> $statements
5443
*
55-
* @return CypherList<SummarizedResult<CypherMap>>
44+
* @return CypherList<SummarizedResult>
5645
*/
5746
public function runStatements(iterable $statements): CypherList
5847
{
@@ -62,7 +51,7 @@ public function runStatements(iterable $statements): CypherList
6251
/**
6352
* @param iterable<Statement> $statements
6453
*
65-
* @return CypherList<SummarizedResult<CypherMap>>
54+
* @return CypherList<SummarizedResult>
6655
*/
6756
public function commit(iterable $statements = []): CypherList
6857
{

0 commit comments

Comments
 (0)