Skip to content

Commit 3f74611

Browse files
committed
made all collections immutable
1 parent dd7229a commit 3f74611

22 files changed

+106
-81
lines changed

src/Bolt/BoltDriver.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
namespace Laudis\Neo4j\Bolt;
1515

1616
use Bolt\connection\StreamSocket;
17-
use Ds\Map;
18-
use Ds\Vector;
1917
use Exception;
2018
use function is_string;
2119
use Laudis\Neo4j\Authentication\Authenticate;
@@ -27,13 +25,15 @@
2725
use Laudis\Neo4j\Contracts\SessionInterface;
2826
use Laudis\Neo4j\Databags\DriverConfiguration;
2927
use Laudis\Neo4j\Databags\SessionConfiguration;
30-
use Laudis\Neo4j\Formatter\BasicFormatter;
28+
use Laudis\Neo4j\Formatter\OGMFormatter;
3129
use Psr\Http\Message\UriInterface;
3230

3331
/**
3432
* @template T
3533
*
3634
* @implements DriverInterface<T>
35+
*
36+
* @psalm-import-type OGMResults from \Laudis\Neo4j\Formatter\OGMFormatter
3737
*/
3838
final class BoltDriver implements DriverInterface
3939
{
@@ -65,11 +65,11 @@ public function __construct(
6565
/**
6666
* @param string|UriInterface $uri
6767
*
68-
* @return self<Vector<Map<string, scalar|array|null>>>
68+
* @return self<OGMResults>
6969
*/
7070
public static function create($uri, ?DriverConfiguration $configuration = null, ?AuthenticateInterface $authenticate = null): self
7171
{
72-
return self::createWithFormatter($uri, new BasicFormatter(), $configuration, $authenticate);
72+
return self::createWithFormatter($uri, OGMFormatter::create(), $configuration, $authenticate);
7373
}
7474

7575
/**

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Laudis\Neo4j\Databags\Statement;
2323
use Laudis\Neo4j\Exception\Neo4jException;
2424
use Laudis\Neo4j\ParameterHelper;
25+
use Laudis\Neo4j\Types\CypherList;
2526
use Throwable;
2627

2728
/**
@@ -48,7 +49,7 @@ public function __construct(string $database, FormatterInterface $formatter, Bol
4849
$this->database = $database;
4950
}
5051

51-
public function commit(iterable $statements = []): Vector
52+
public function commit(iterable $statements = []): CypherList
5253
{
5354
$tbr = $this->runStatements($statements);
5455

@@ -90,7 +91,7 @@ public function runStatement(Statement $statement)
9091
return $this->runStatements([$statement])->first();
9192
}
9293

93-
public function runStatements(iterable $statements): Vector
94+
public function runStatements(iterable $statements): CypherList
9495
{
9596
/** @var Vector<T> $tbr */
9697
$tbr = new Vector();
@@ -108,6 +109,6 @@ public function runStatements(iterable $statements): Vector
108109
$tbr->push($this->formatter->formatBoltResult($meta, $results, $this->bolt));
109110
}
110111

111-
return $tbr;
112+
return new CypherList($tbr);
112113
}
113114
}

src/Bolt/Session.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Laudis\Neo4j\Databags\Statement;
3030
use Laudis\Neo4j\Databags\TransactionConfiguration;
3131
use Laudis\Neo4j\Exception\Neo4jException;
32+
use Laudis\Neo4j\Types\CypherList;
3233
use Psr\Http\Message\UriInterface;
3334

3435
/**
@@ -67,13 +68,9 @@ public function __construct(
6768
$this->auth = $auth;
6869
}
6970

70-
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): Vector
71+
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList
7172
{
72-
$transaction = $this->openTransaction();
73-
$tbr = $transaction->runStatements($statements);
74-
$transaction->commit();
75-
76-
return $tbr;
73+
return $this->openTransaction()->commit($statements);
7774
}
7875

7976
public function openTransaction(iterable $statements = null, ?TransactionConfiguration $config = null): UnmanagedTransactionInterface

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace Laudis\Neo4j;
1515

1616
use Ds\Map;
17-
use Ds\Vector;
1817
use function in_array;
1918
use InvalidArgumentException;
2019
use function is_array;
@@ -32,6 +31,7 @@
3231
use Laudis\Neo4j\Databags\TransactionConfiguration;
3332
use Laudis\Neo4j\Http\HttpDriver;
3433
use Laudis\Neo4j\Neo4j\Neo4jDriver;
34+
use Laudis\Neo4j\Types\CypherList;
3535
use Psr\Http\Message\UriInterface;
3636
use function sprintf;
3737

@@ -79,7 +79,7 @@ public function runStatement(Statement $statement, ?string $alias = null)
7979
return $this->startSession($alias)->runStatement($statement);
8080
}
8181

82-
public function runStatements(iterable $statements, ?string $alias = null): Vector
82+
public function runStatements(iterable $statements, ?string $alias = null): CypherList
8383
{
8484
return $this->startSession($alias)->runStatements($statements);
8585
}

src/Contracts/ClientInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Contracts;
1515

16-
use Ds\Vector;
1716
use Laudis\Neo4j\Databags\Statement;
1817
use Laudis\Neo4j\Databags\TransactionConfiguration;
1918
use Laudis\Neo4j\Exception\Neo4jException;
19+
use Laudis\Neo4j\Types\CypherList;
2020

2121
/**
2222
* @template T
@@ -50,9 +50,9 @@ public function runStatement(Statement $statement, ?string $alias = null);
5050
*
5151
* @throws Neo4jException
5252
*
53-
* @return Vector<T>
53+
* @return CypherList<T>
5454
*/
55-
public function runStatements(iterable $statements, ?string $alias = null): Vector;
55+
public function runStatements(iterable $statements, ?string $alias = null): CypherList;
5656

5757
/**
5858
* Opens a transaction over the connection with the given alias if provided, the master alias otherwise.

src/Contracts/FormatterInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace Laudis\Neo4j\Contracts;
1515

1616
use Bolt\Bolt;
17-
use Ds\Vector;
1817
use JsonException;
18+
use Laudis\Neo4j\Types\CypherList;
1919
use Psr\Http\Message\RequestInterface;
2020
use Psr\Http\Message\ResponseInterface;
2121

@@ -78,9 +78,9 @@ public function formatBoltResult(array $meta, array $results, Bolt $bolt);
7878
*
7979
* @throws JsonException
8080
*
81-
* @return Vector<T>
81+
* @return CypherList<T>
8282
*/
83-
public function formatHttpResult(ResponseInterface $response, array $body): Vector;
83+
public function formatHttpResult(ResponseInterface $response, array $body): CypherList;
8484

8585
public function decorateRequest(RequestInterface $request): RequestInterface;
8686

src/Contracts/SessionInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace Laudis\Neo4j\Contracts;
1515

16-
use Ds\Vector;
1716
use Laudis\Neo4j\Databags\Statement;
1817
use Laudis\Neo4j\Databags\TransactionConfiguration;
1918
use Laudis\Neo4j\Exception\Neo4jException;
19+
use Laudis\Neo4j\Types\CypherList;
2020

2121
/**
2222
* @template T
@@ -28,9 +28,9 @@ interface SessionInterface
2828
*
2929
* @throws Neo4jException
3030
*
31-
* @return Vector<T>
31+
* @return CypherList<T>
3232
*/
33-
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): Vector;
33+
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList;
3434

3535
/**
3636
* @return T

src/Contracts/TransactionInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace Laudis\Neo4j\Contracts;
1515

16-
use Ds\Vector;
1716
use Laudis\Neo4j\Databags\Statement;
1817
use Laudis\Neo4j\Exception\Neo4jException;
18+
use Laudis\Neo4j\Types\CypherList;
1919

2020
/**
2121
* @template T
@@ -39,7 +39,7 @@ public function runStatement(Statement $statement);
3939
*
4040
* @throws Neo4jException
4141
*
42-
* @return Vector<T>
42+
* @return CypherList<T>
4343
*/
44-
public function runStatements(iterable $statements): Vector;
44+
public function runStatements(iterable $statements): CypherList;
4545
}

src/Contracts/UnmanagedTransactionInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
namespace Laudis\Neo4j\Contracts;
1515

16-
use Ds\Vector;
1716
use Laudis\Neo4j\Databags\Statement;
17+
use Laudis\Neo4j\Types\CypherList;
1818

1919
/**
2020
* @template T
@@ -26,9 +26,9 @@ interface UnmanagedTransactionInterface extends TransactionInterface
2626
/**
2727
* @param iterable<Statement> $statements
2828
*
29-
* @return Vector<T>
29+
* @return CypherList<T>
3030
*/
31-
public function commit(iterable $statements = []): Vector;
31+
public function commit(iterable $statements = []): CypherList;
3232

3333
public function rollback(): void;
3434
}

src/Formatter/BasicFormatter.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use function is_array;
2525
use function is_object;
2626
use Laudis\Neo4j\Contracts\FormatterInterface;
27+
use Laudis\Neo4j\Types\CypherList;
28+
use Laudis\Neo4j\Types\CypherMap;
2729
use Psr\Http\Message\RequestInterface;
2830
use Psr\Http\Message\ResponseInterface;
2931
use UnexpectedValueException;
@@ -33,46 +35,52 @@
3335
* @psalm-import-type CypherRowResponse from \Laudis\Neo4j\Contracts\FormatterInterface
3436
* @psalm-import-type CypherResponse from \Laudis\Neo4j\Contracts\FormatterInterface
3537
* @psalm-import-type CypherResponseSet from \Laudis\Neo4j\Contracts\FormatterInterface
36-
* @implements FormatterInterface<Vector<Map<string, scalar|array|null>>>
38+
*
39+
* @psalm-type BasicResults = CypherList<CypherMap<scalar|array|null>>
40+
*
41+
* @implements FormatterInterface<BasicResults>
3742
*/
3843
final class BasicFormatter implements FormatterInterface
3944
{
4045
/**
4146
* @param array{fields: array<int, string>} $meta
4247
* @param array<array-key, array> $results
4348
*
44-
* @return Vector<Map<string, scalar|array|null>>
49+
* @return CypherList<CypherMap<array|scalar|null>>
4550
*/
46-
public function formatBoltResult(array $meta, array $results, Bolt $bolt): Vector
51+
public function formatBoltResult(array $meta, array $results, Bolt $bolt): CypherList
4752
{
4853
$results = array_slice($results, 0, count($results) - 1);
4954

55+
/** @var Vector<CypherMap<scalar|array|null>> */
5056
$tbr = new Vector();
5157
foreach ($results as $result) {
5258
$tbr->push($this->formatRow($meta, $result));
5359
}
5460

55-
return $tbr;
61+
return new CypherList($tbr);
5662
}
5763

58-
public function formatHttpResult(ResponseInterface $response, array $body): Vector
64+
public function formatHttpResult(ResponseInterface $response, array $body): CypherList
5965
{
66+
/** @var Vector<CypherList<CypherMap<scalar|array|null>>> */
6067
$tbr = new Vector();
6168

6269
foreach ($body['results'] as $results) {
6370
$tbr->push($this->buildResult($results));
6471
}
6572

66-
return $tbr;
73+
return new CypherList($tbr);
6774
}
6875

6976
/**
7077
* @psalm-param CypherResponse $result
7178
*
72-
* @return Vector<Map<string, scalar|array|null>>
79+
* @return CypherList<CypherMap<scalar|array|null>>
7380
*/
74-
private function buildResult(array $result): Vector
81+
private function buildResult(array $result): CypherList
7582
{
83+
/** @psalm-var Vector<CypherMap<null|scalar|array>> */
7684
$tbr = new Vector();
7785

7886
$columns = $result['columns'];
@@ -84,26 +92,26 @@ private function buildResult(array $result): Vector
8492
foreach ($columns as $index => $key) {
8593
$map->put($key, $vector->get($index));
8694
}
87-
$tbr->push($map);
95+
$tbr->push(new CypherMap($map));
8896
}
8997

90-
return $tbr;
98+
return new CypherList($tbr);
9199
}
92100

93101
/**
94102
* @param array{fields: array<int, string>} $meta
95103
*
96-
* @return Map<string, scalar|array|null>
104+
* @return CypherMap<scalar|array|null>
97105
*/
98-
private function formatRow(array $meta, array $result): Map
106+
private function formatRow(array $meta, array $result): CypherMap
99107
{
100108
/** @var Map<string, scalar|array|null> $map */
101109
$map = new Map();
102110
foreach ($meta['fields'] as $i => $column) {
103111
$map->put($column, $this->mapValue($result[$i]));
104112
}
105113

106-
return $map;
114+
return new CypherMap($map);
107115
}
108116

109117
private function mapPath(Path $path): array

0 commit comments

Comments
 (0)