Skip to content

Commit 897cc49

Browse files
committed
removed final php ds references
1 parent 53a2c2d commit 897cc49

File tree

8 files changed

+40
-55
lines changed

8 files changed

+40
-55
lines changed

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use Bolt\Bolt;
1717
use Bolt\error\MessageException;
18-
use Ds\Vector;
1918
use Exception;
2019
use Laudis\Neo4j\Common\TransactionHelper;
2120
use Laudis\Neo4j\Contracts\ConnectionInterface;
@@ -60,15 +59,15 @@ public function commit(iterable $statements = []): CypherList
6059
$tbr = $this->runStatements($statements);
6160

6261
if ($this->finished) {
63-
throw new Neo4jException(new Vector([new Neo4jError('0', 'Transaction already finished')]));
62+
throw new Neo4jException([new Neo4jError('0', 'Transaction already finished')]);
6463
}
6564

6665
try {
6766
$this->getBolt()->commit();
6867
$this->finished = true;
6968
} catch (Exception $e) {
7069
$code = TransactionHelper::extractCode($e);
71-
throw new Neo4jException(new Vector([new Neo4jError($code ?? '', $e->getMessage())]), $e);
70+
throw new Neo4jException([new Neo4jError($code ?? '', $e->getMessage())], $e);
7271
}
7372

7473
return $tbr;
@@ -77,15 +76,15 @@ public function commit(iterable $statements = []): CypherList
7776
public function rollback(): void
7877
{
7978
if ($this->finished) {
80-
throw new Neo4jException(new Vector([new Neo4jError('0', 'Transaction already finished')]));
79+
throw new Neo4jException([new Neo4jError('0', 'Transaction already finished')]);
8180
}
8281

8382
try {
8483
$this->connection->getImplementation()->rollback();
8584
$this->finished = true;
8685
} catch (Exception $e) {
8786
$code = TransactionHelper::extractCode($e) ?? '';
88-
throw new Neo4jException(new Vector([new Neo4jError($code, $e->getMessage())]), $e);
87+
throw new Neo4jException([new Neo4jError($code, $e->getMessage())], $e);
8988
}
9089
}
9190

@@ -110,8 +109,8 @@ public function runStatement(Statement $statement)
110109
*/
111110
public function runStatements(iterable $statements): CypherList
112111
{
113-
/** @var Vector<T> $tbr */
114-
$tbr = new Vector();
112+
/** @var list<T> $tbr */
113+
$tbr = [];
115114
foreach ($statements as $statement) {
116115
$extra = ['db' => $this->database];
117116
$parameters = ParameterHelper::formatParameters($statement->getParameters());
@@ -126,18 +125,18 @@ public function runStatements(iterable $statements): CypherList
126125
} catch (Throwable $e) {
127126
if ($e instanceof MessageException) {
128127
$code = TransactionHelper::extractCode($e) ?? '';
129-
throw new Neo4jException(new Vector([new Neo4jError($code, $e->getMessage())]), $e);
128+
throw new Neo4jException([new Neo4jError($code, $e->getMessage())], $e);
130129
}
131130
throw $e;
132131
}
133-
$tbr->push($this->formatter->formatBoltResult(
132+
$tbr[] = $this->formatter->formatBoltResult(
134133
$meta,
135134
$results,
136135
$this->connection,
137136
$run - $start,
138137
$end - $start,
139138
$statement
140-
));
139+
);
141140
}
142141

143142
return new CypherList($tbr);

src/Bolt/Session.php

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

1616
use Bolt\Bolt;
17-
use Ds\Vector;
1817
use Exception;
1918
use Laudis\Neo4j\Common\TransactionHelper;
2019
use Laudis\Neo4j\Contracts\AuthenticateInterface;
@@ -161,14 +160,14 @@ private function startTransaction(TransactionConfiguration $config, SessionConfi
161160
$begin = $bolt->getImplementation()->begin(['db' => $this->config->getDatabase()]);
162161

163162
if (!$begin) {
164-
throw new Neo4jException(new Vector([new Neo4jError('', 'Cannot open new transaction')]));
163+
throw new Neo4jException([new Neo4jError('', 'Cannot open new transaction')]);
165164
}
166165
} catch (Exception $e) {
167166
if ($e instanceof Neo4jException) {
168167
throw $e;
169168
}
170169
$code = TransactionHelper::extractCode($e) ?? '';
171-
throw new Neo4jException(new Vector([new Neo4jError($code, $e->getMessage())]), $e);
170+
throw new Neo4jException([new Neo4jError($code, $e->getMessage())], $e);
172171
}
173172

174173
return new BoltUnmanagedTransaction($this->config->getDatabase(), $this->formatter, $bolt);

src/Contracts/DriverInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @psalm-type ParsedUrl = array{host: string, pass: string|null, path: string, port: int, query: array<string,string>, scheme: string, user: string|null}
2222
*
23-
* @psalm-type BasicDriver = DriverInterface<\Ds\Vector<\Ds\Map<string, scalar|array|null>>>
23+
* @psalm-type BasicDriver = DriverInterface<\Laudis\Neo4j\Formatter\CypherList<\Laudis\Neo4j\Formatter\CypherMap<string, scalar|array|null>>>
2424
*/
2525
interface DriverInterface
2626
{

src/Exception/Neo4jException.php

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

1414
namespace Laudis\Neo4j\Exception;
1515

16-
use Ds\Vector;
1716
use Laudis\Neo4j\Databags\Neo4jError;
1817
use RuntimeException;
1918
use Throwable;
2019

2120
final class Neo4jException extends RuntimeException
2221
{
2322
private const MESSAGE_TEMPLATE = 'Neo4j errors detected. First one with code "%s" and message "%s"';
24-
/** @var Vector<Neo4jError> */
25-
private Vector $errors;
23+
/** @var non-empty-list<Neo4jError> */
24+
private array $errors;
2625

2726
/**
28-
* @param Vector<Neo4jError> $errors
27+
* @param non-empty-list<Neo4jError> $errors
2928
*/
30-
public function __construct(Vector $errors, Throwable $previous = null)
29+
public function __construct(array $errors, Throwable $previous = null)
3130
{
32-
$error = $errors->first();
31+
$error = $errors[0];
3332
$message = sprintf(self::MESSAGE_TEMPLATE, $error->getCode(), $error->getMessage());
3433
parent::__construct($message, 0, $previous);
3534
$this->errors = $errors;
3635
}
3736

3837
/**
39-
* @return Vector<Neo4jError>
38+
* @return non-empty-list<Neo4jError>
4039
*/
41-
public function getErrors(): Vector
40+
public function getErrors(): array
4241
{
4342
return $this->errors;
4443
}
4544

4645
public function getNeo4jCode(): string
4746
{
48-
return $this->errors->first()->getCode();
47+
return $this->errors[0]->getCode();
4948
}
5049
}

src/Http/HttpHelper.php

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

1616
use function array_merge;
17-
use Ds\Vector;
17+
use function count;
1818
use function json_decode;
1919
use function json_encode;
2020
use const JSON_THROW_ON_ERROR;
@@ -41,18 +41,18 @@ public static function interpretResponse(ResponseInterface $response): array
4141
{
4242
$contents = $response->getBody()->getContents();
4343
if ($response->getStatusCode() >= 400) {
44-
throw new Neo4jException(new Vector([new Neo4jError((string) $response->getStatusCode(), $contents)]));
44+
throw new Neo4jException([new Neo4jError((string) $response->getStatusCode(), $contents)]);
4545
}
4646

4747
/** @var CypherResponseSet $body */
4848
$body = json_decode($contents, true, 512, JSON_THROW_ON_ERROR);
4949

50-
$errors = new Vector();
50+
$errors = [];
5151
foreach (($body['errors'] ?? []) as $error) {
52-
$errors->push(new Neo4jError($error['code'], $error['message']));
52+
$errors[] = new Neo4jError($error['code'], $error['message']);
5353
}
5454

55-
if (!$errors->isEmpty()) {
55+
if (count($errors) !== 0) {
5656
throw new Neo4jException($errors);
5757
}
5858

src/ParameterHelper.php

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

1616
use function count;
17-
use Ds\Map;
18-
use Ds\Sequence;
19-
use Ds\Vector;
2017
use function gettype;
2118
use InvalidArgumentException;
2219
use function is_array;
@@ -38,7 +35,7 @@ final class ParameterHelper
3835
*/
3936
public static function asList(iterable $iterable): CypherList
4037
{
41-
return new CypherList(new Vector($iterable));
38+
return new CypherList($iterable);
4239
}
4340

4441
/**
@@ -50,13 +47,7 @@ public static function asList(iterable $iterable): CypherList
5047
*/
5148
public static function asMap(iterable $iterable): CypherMap
5249
{
53-
/** @var Map<string, mixed> $map */
54-
$map = new Map();
55-
foreach ($iterable as $key => $value) {
56-
$map->put((string) $key, $value);
57-
}
58-
59-
return new CypherMap($map);
50+
return new CypherMap($iterable);
6051
}
6152

6253
/**
@@ -104,7 +95,7 @@ private static function filterInvalidType($value)
10495
*/
10596
private static function emptySequenceToArray($value): ?array
10697
{
107-
if (($value instanceof Sequence && $value->count() === 0) ||
98+
if ((($value instanceof CypherList || $value instanceof CypherMap) && $value->count() === 0) ||
10899
(is_array($value) && count($value) === 0)) {
109100
return [];
110101
}
@@ -117,7 +108,7 @@ private static function emptySequenceToArray($value): ?array
117108
*/
118109
private static function emptyDictionaryToStdClass($value): ?stdClass
119110
{
120-
if (($value instanceof Map || $value instanceof CypherMap) && $value->count() === 0) {
111+
if (($value instanceof CypherMap) && $value->count() === 0) {
121112
return new stdClass();
122113
}
123114

@@ -139,21 +130,21 @@ private static function filledIterableToArray($value): ?array
139130
/**
140131
* @param iterable<iterable|scalar|null> $parameters
141132
*
142-
* @return Map<array-key, iterable|scalar|stdClass|null>
133+
* @return CypherMap<iterable|scalar|stdClass|null>
143134
*/
144-
public static function formatParameters(iterable $parameters): Map
135+
public static function formatParameters(iterable $parameters): CypherMap
145136
{
146-
/** @var Map<array-key, iterable|scalar|stdClass|null> $tbr */
147-
$tbr = new Map();
137+
/** @var array<string, iterable|scalar|stdClass|null> $tbr */
138+
$tbr = [];
148139
foreach ($parameters as $key => $value) {
149140
if (!(is_int($key) || is_string($key))) {
150141
$msg = 'The parameters must have an integer or string as key values, '.gettype($key).' received.';
151142
throw new InvalidArgumentException($msg);
152143
}
153-
$tbr->put($key, self::asParameter($value));
144+
$tbr[(string) $key] = self::asParameter($value);
154145
}
155146

156-
return $tbr;
147+
return new CypherMap($tbr);
157148
}
158149

159150
private static function iterableToArray(iterable $value): array

tests/Unit/Neo4jExceptionTest.php

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

1414
namespace Laudis\Neo4j\Tests\Unit;
1515

16-
use Ds\Vector;
1716
use Error;
1817
use Laudis\Neo4j\Databags\Neo4jError;
1918
use Laudis\Neo4j\Exception\Neo4jException;
2019
use PHPUnit\Framework\TestCase;
2120

2221
final class Neo4jExceptionTest extends TestCase
2322
{
24-
private Vector $errors;
23+
private array $errors;
2524
private Error $previous;
2625
private Neo4jException $exception;
2726

2827
protected function setUp(): void
2928
{
3029
parent::setUp();
31-
$this->errors = new Vector([new Neo4jError('0', 'abc'), new Neo4jError('1', 'efg')]);
30+
$this->errors = [new Neo4jError('0', 'abc'), new Neo4jError('1', 'efg')];
3231
$this->previous = new Error();
3332
$this->exception = new Neo4jException($this->errors, $this->previous);
3433
}

tests/Unit/ParameterHelperTest.php

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

1414
namespace Laudis\Neo4j\Tests\Unit;
1515

16-
use Ds\Map;
17-
use Ds\Vector;
1816
use InvalidArgumentException;
1917
use Iterator;
2018
use Laudis\Neo4j\ParameterHelper;
@@ -119,15 +117,15 @@ public function testFormatParameterInvalidIterable2(): void
119117

120118
public function testAsParameterEmptyVector(): void
121119
{
122-
$result = ParameterHelper::asParameter(new Vector());
120+
$result = ParameterHelper::asParameter([]);
123121
self::assertIsArray($result);
124122
self::assertCount(0, $result);
125123
}
126124

127125
public function testAsParameterEmptyMap(): void
128126
{
129-
$result = ParameterHelper::asParameter(new Map());
130-
self::assertInstanceOf(stdClass::class, $result);
127+
$result = ParameterHelper::asParameter([]);
128+
self::assertIsArray($result);
131129
}
132130

133131
public function testAsParameterEmptyArray(): void

0 commit comments

Comments
 (0)