Skip to content

Commit 3bc2fe5

Browse files
committed
feat: Remove OGMFormatter and FormatterInterface
1 parent f7c87b8 commit 3bc2fe5

25 files changed

+74
-434
lines changed

src/Basic/Client.php

-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@
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(
3225
private readonly ClientInterface $client
3326
) {}

src/Basic/Driver.php

-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@
2323
use Laudis\Neo4j\Types\CypherMap;
2424
use Psr\Http\Message\UriInterface;
2525

26-
/**
27-
* @implements DriverInterface<SummarizedResult<CypherMap>>
28-
*/
2926
final class Driver implements DriverInterface
3027
{
3128
/**
32-
* @param DriverInterface<SummarizedResult<CypherMap>> $driver
33-
*
3429
* @psalm-external-mutation-free
3530
*/
3631
public function __construct(
@@ -52,7 +47,6 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
5247

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

5852
return new self($driver);

src/Basic/Session.php

+1-12
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,29 @@
2121
use Laudis\Neo4j\Types\CypherList;
2222
use Laudis\Neo4j\Types\CypherMap;
2323

24-
/**
25-
* @implements SessionInterface<SummarizedResult<CypherMap>>
26-
*/
2724
final class Session implements SessionInterface
2825
{
29-
/**
30-
* @param SessionInterface<SummarizedResult<CypherMap>> $session
31-
*/
3226
public function __construct(
3327
private readonly SessionInterface $session
3428
) {}
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

-7
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@
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(
3124
private readonly UnmanagedTransactionInterface $tsx
3225
) {}

src/Bolt/BoltDriver.php

+5-22
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,33 @@
2323
use Laudis\Neo4j\Common\Uri;
2424
use Laudis\Neo4j\Contracts\AuthenticateInterface;
2525
use Laudis\Neo4j\Contracts\DriverInterface;
26-
use Laudis\Neo4j\Contracts\FormatterInterface;
2726
use Laudis\Neo4j\Contracts\SessionInterface;
2827
use Laudis\Neo4j\Databags\DriverConfiguration;
2928
use Laudis\Neo4j\Databags\SessionConfiguration;
30-
use Laudis\Neo4j\Formatter\OGMFormatter;
29+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
3130
use Psr\Http\Message\UriInterface;
3231
use Psr\Log\LogLevel;
3332

3433
/**
3534
* Drives a singular bolt connections.
3635
*
37-
* @template T
38-
*
39-
* @implements DriverInterface<T>
40-
*
41-
* @psalm-import-type OGMResults from OGMFormatter
36+
* @psalm-import-type OGMResults from SummarizedResultFormatter
4237
*/
4338
final class BoltDriver implements DriverInterface
4439
{
4540
/**
46-
* @param FormatterInterface<T> $formatter
47-
*
4841
* @psalm-mutation-free
4942
*/
5043
public function __construct(
5144
private readonly UriInterface $parsedUrl,
5245
private readonly ConnectionPool $pool,
53-
private readonly FormatterInterface $formatter
46+
private readonly SummarizedResultFormatter $formatter
5447
) {}
5548

5649
/**
57-
* @template U
58-
*
59-
* @param FormatterInterface<U> $formatter
60-
*
61-
* @return (
62-
* func_num_args() is 5
63-
* ? self<U>
64-
* : self<OGMResults>
65-
* )
66-
*
6750
* @psalm-suppress MixedReturnTypeCoercion
6851
*/
69-
public static function create(string|UriInterface $uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null, ?FormatterInterface $formatter = null): self
52+
public static function create(string|UriInterface $uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null, ?SummarizedResultFormatter $formatter = null): self
7053
{
7154
if (is_string($uri)) {
7255
$uri = Uri::create($uri);
@@ -80,7 +63,7 @@ public static function create(string|UriInterface $uri, ?DriverConfiguration $co
8063
return new self(
8164
$uri,
8265
ConnectionPool::create($uri, $authenticate, $configuration, $semaphore),
83-
$formatter ?? OGMFormatter::create(),
66+
$formatter ?? SummarizedResultFormatter::create(),
8467
);
8568
}
8669

src/Bolt/BoltResult.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Laudis\Neo4j\Bolt;
1515

16+
use Laudis\Neo4j\Formatter\SummarizedResultFormatter;
1617
use function array_splice;
1718
use function count;
1819

@@ -21,10 +22,9 @@
2122
use function in_array;
2223

2324
use Iterator;
24-
use Laudis\Neo4j\Contracts\FormatterInterface;
2525

2626
/**
27-
* @psalm-import-type BoltCypherStats from FormatterInterface
27+
* @psalm-import-type BoltCypherStats from SummarizedResultFormatter
2828
*
2929
* @implements Iterator<int, list>
3030
*/

src/Bolt/BoltUnmanagedTransaction.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Laudis\Neo4j\Databags\BookmarkHolder;
1919
use Laudis\Neo4j\Databags\SessionConfiguration;
2020
use Laudis\Neo4j\Databags\Statement;
21+
use Laudis\Neo4j\Databags\SummarizedResult;
2122
use Laudis\Neo4j\Databags\TransactionConfiguration;
2223
use Laudis\Neo4j\Enum\TransactionState;
2324
use Laudis\Neo4j\Exception\ClientException;
@@ -33,10 +34,6 @@
3334
/**
3435
* Manages a transaction over the bolt protocol.
3536
*
36-
* @template T
37-
*
38-
* @implements UnmanagedTransactionInterface<T>
39-
*
4037
* @psalm-import-type BoltMeta from SummarizedResultFormatter
4138
*/
4239
final class BoltUnmanagedTransaction implements UnmanagedTransactionInterface
@@ -59,6 +56,8 @@ public function __construct(
5956

6057
/**
6158
* @throws ClientException|Throwable
59+
*
60+
* @return CypherList<SummarizedResult>
6261
*/
6362
public function commit(iterable $statements = []): CypherList
6463
{
@@ -78,10 +77,8 @@ public function commit(iterable $statements = []): CypherList
7877

7978
// Force the results to pull all the results.
8079
// After a commit, the connection will be in the ready state, making it impossible to use PULL
81-
$tbr = $this->runStatements($statements)->each(static function ($list) {
82-
if ($list instanceof AbstractCypherSequence) {
83-
$list->preload();
84-
}
80+
$tbr = $this->runStatements($statements)->each(static function (CypherList $list) {
81+
$list->preload();
8582
});
8683

8784
$this->connection->commit();
@@ -113,15 +110,15 @@ public function rollback(): void
113110
/**
114111
* @throws Throwable
115112
*/
116-
public function run(string $statement, iterable $parameters = [])
113+
public function run(string $statement, iterable $parameters = []): SummarizedResult
117114
{
118115
return $this->runStatement(new Statement($statement, $parameters));
119116
}
120117

121118
/**
122119
* @throws Throwable
123120
*/
124-
public function runStatement(Statement $statement)
121+
public function runStatement(Statement $statement): SummarizedResult
125122
{
126123
$parameters = ParameterHelper::formatParameters($statement->getParameters(), $this->connection->getProtocol());
127124
$start = microtime(true);
@@ -159,10 +156,11 @@ public function runStatement(Statement $statement)
159156

160157
/**
161158
* @throws Throwable
159+
*
160+
* @return CypherList<SummarizedResult>
162161
*/
163162
public function runStatements(iterable $statements): CypherList
164163
{
165-
/** @var list<T> $tbr */
166164
$tbr = [];
167165
foreach ($statements as $statement) {
168166
$tbr[] = $this->runStatement($statement);

src/Bolt/Session.php

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function __construct(
5959
$this->bookmarkHolder = new BookmarkHolder(Bookmark::from($config->getBookmarks()));
6060
}
6161

62+
/**
63+
* @return CypherList<SummarizedResult>
64+
*/
6265
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList
6366
{
6467
$tbr = [];

src/Client.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,30 @@
2121
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
2222
use Laudis\Neo4j\Databags\SessionConfiguration;
2323
use Laudis\Neo4j\Databags\Statement;
24+
use Laudis\Neo4j\Databags\SummarizedResult;
2425
use Laudis\Neo4j\Databags\TransactionConfiguration;
2526
use Laudis\Neo4j\Enum\AccessMode;
2627
use Laudis\Neo4j\Types\CypherList;
2728

2829
/**
2930
* A collection of drivers with methods to run queries though them.
30-
*
31-
* @template ResultFormat
32-
*
33-
* @implements ClientInterface<ResultFormat>
3431
*/
3532
final class Client implements ClientInterface
3633
{
3734
/**
38-
* @var array<string, list<UnmanagedTransactionInterface<ResultFormat>>>
35+
* @var array<string, list<UnmanagedTransactionInterface>>
3936
*/
4037
private array $boundTransactions = [];
4138

4239
/**
43-
* @var array<string, SessionInterface<ResultFormat>>
40+
* @var array<string, SessionInterface>
4441
*/
4542
private array $boundSessions = [];
4643

4744
/**
4845
* @psalm-mutation-free
4946
*
50-
* @param DriverSetupManager<ResultFormat> $driverSetups
47+
* @param DriverSetupManager $driverSetups
5148
*/
5249
public function __construct(
5350
private readonly DriverSetupManager $driverSetups,
@@ -70,12 +67,12 @@ public function getDefaultTransactionConfiguration(): TransactionConfiguration
7067
return $this->defaultTransactionConfiguration;
7168
}
7269

73-
public function run(string $statement, iterable $parameters = [], ?string $alias = null)
70+
public function run(string $statement, iterable $parameters = [], ?string $alias = null): SummarizedResult
7471
{
7572
return $this->runStatement(Statement::create($statement, $parameters), $alias);
7673
}
7774

78-
public function runStatement(Statement $statement, ?string $alias = null)
75+
public function runStatement(Statement $statement, ?string $alias = null): SummarizedResult
7976
{
8077
return $this->runStatements([$statement], $alias)->first();
8178
}
@@ -86,6 +83,7 @@ private function getRunner(?string $alias = null): TransactionInterface|SessionI
8683

8784
if (array_key_exists($alias, $this->boundTransactions) &&
8885
count($this->boundTransactions[$alias]) > 0) {
86+
/** @psalm-suppress PossiblyNullArrayOffset */
8987
return $this->boundTransactions[$alias][array_key_last($this->boundTransactions[$alias])];
9088
}
9189

@@ -126,9 +124,6 @@ public function getDriver(?string $alias): DriverInterface
126124
return $this->driverSetups->getDriver($this->defaultSessionConfiguration, $alias);
127125
}
128126

129-
/**
130-
* @return SessionInterface<ResultFormat>
131-
*/
132127
private function startSession(?string $alias, SessionConfiguration $configuration): SessionInterface
133128
{
134129
return $this->getDriver($alias)->createSession($configuration);
@@ -187,7 +182,7 @@ public function rollbackBoundTransaction(?string $alias = null, int $depth = 1):
187182
}
188183

189184
/**
190-
* @param callable(UnmanagedTransactionInterface<ResultFormat>): void $handler
185+
* @param callable(UnmanagedTransactionInterface): void $handler
191186
*/
192187
private function popTransactions(callable $handler, ?string $alias = null, int $depth = 1): void
193188
{

0 commit comments

Comments
 (0)