Skip to content

Commit be6a56c

Browse files
committed
fixed all typing errors and simplified maps and lists
1 parent 4579b9f commit be6a56c

26 files changed

+1170
-1072
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

composer.json

Lines changed: 2 additions & 2 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",
51+
"vimeo/psalm": "^6.5",
5252
"friendsofphp/php-cs-fixer": "3.68.5",
53-
"psalm/plugin-phpunit": "^0.18",
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/Bolt/BoltResult.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* @psalm-import-type BoltCypherStats from SummarizedResultFormatter
2828
*
29-
* @implements Iterator<int, list>
29+
* @implements Iterator<int, list<mixed>>
3030
*/
3131
final class BoltResult implements Iterator
3232
{
@@ -71,7 +71,7 @@ public function getIt(): Generator
7171
}
7272

7373
/**
74-
* @return Generator<int, list>
74+
* @return Generator<int, list<mixed>>
7575
*/
7676
public function iterator(): Generator
7777
{
@@ -113,10 +113,15 @@ private function fetchResults(): void
113113
}
114114

115115
/**
116-
* @return list
116+
* @psalm-suppress InvalidNullableReturnType
117+
*
118+
* @return list<mixed>
117119
*/
118120
public function current(): array
119121
{
122+
/**
123+
* @psalm-suppress NullableReturnStatement
124+
*/
120125
return $this->getIt()->current();
121126
}
122127

src/Bolt/BoltUnmanagedTransaction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function __construct(
5555
}
5656

5757
/**
58+
* @param iterable<Statement> $statements
59+
*
5860
* @throws ClientException|Throwable
5961
*
6062
* @return CypherList<SummarizedResult>
@@ -155,6 +157,8 @@ public function runStatement(Statement $statement): SummarizedResult
155157
}
156158

157159
/**
160+
* @param iterable<Statement> $statements
161+
*
158162
* @throws Throwable
159163
*
160164
* @return CypherList<SummarizedResult>

src/Bolt/Session.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function __construct(
6060
}
6161

6262
/**
63+
* @param iterable<Statement> $statements
64+
*
6365
* @return CypherList<SummarizedResult>
6466
*/
6567
public function runStatements(iterable $statements, ?TransactionConfiguration $config = null): CypherList
@@ -120,6 +122,9 @@ public function transaction(callable $tsxHandler, ?TransactionConfiguration $con
120122
return $this->writeTransaction($tsxHandler, $config);
121123
}
122124

125+
/**
126+
* @param iterable<Statement> $statements
127+
*/
123128
public function beginTransaction(?iterable $statements = null, ?TransactionConfiguration $config = null): UnmanagedTransactionInterface
124129
{
125130
$this->getLogger()?->log(LogLevel::INFO, 'Beginning transaction', ['statements' => $statements, 'config' => $config]);

src/Common/DriverSetupManager.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public function withSetup(DriverSetup $setup, ?string $alias = null, ?int $prior
8181

8282
$setups = $this->driverSetups;
8383

84-
/** @var SplPriorityQueue<int, DriverSetup> */
85-
$setups[$alias] ??= new SplPriorityQueue();
84+
/** @var SplPriorityQueue<int, DriverSetup> $splPriorityQueue */
85+
$splPriorityQueue = new SplPriorityQueue();
86+
$setups[$alias] ??= $splPriorityQueue;
8687
/** @psalm-suppress ImpureMethodCall */
8788
$setups[$alias]->insert($setup, $priority ?? 0);
8889

src/Common/TransactionHelper.php

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

1414
namespace Laudis\Neo4j\Common;
1515

16+
use Laudis\Neo4j\Contracts\CypherSequence;
1617
use Laudis\Neo4j\Contracts\TransactionInterface;
1718
use Laudis\Neo4j\Contracts\UnmanagedTransactionInterface;
1819
use Laudis\Neo4j\Exception\Neo4jException;
19-
use Laudis\Neo4j\Types\AbstractCypherSequence;
2020

2121
final class TransactionHelper
2222
{
@@ -55,7 +55,7 @@ public static function retry(callable $tsxFactory, callable $tsxHandler)
5555

5656
private static function triggerLazyResult(mixed $tbr): void
5757
{
58-
if ($tbr instanceof AbstractCypherSequence) {
58+
if ($tbr instanceof CypherSequence) {
5959
$tbr->preload();
6060
}
6161
}

src/Contracts/CypherSequence.php

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Neo4j PHP Client and Driver package.
7+
*
8+
* (c) Nagels <https://nagels.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Laudis\Neo4j\Contracts;
15+
16+
use Countable;
17+
use Iterator;
18+
use JsonSerializable;
19+
use Laudis\Neo4j\Types\CypherList;
20+
use Laudis\Neo4j\Types\CypherMap;
21+
use Laudis\Neo4j\Types\Map;
22+
23+
/**
24+
* Abstract immutable sequence with basic functional methods.
25+
*
26+
* @template TValue
27+
*/
28+
interface CypherSequence extends Countable, JsonSerializable
29+
{
30+
/**
31+
* Copies the sequence.
32+
*
33+
* @return self<TValue>
34+
*
35+
* @psalm-mutation-free
36+
*/
37+
public function copy(): self;
38+
39+
/**
40+
* Returns whether the sequence is empty.
41+
*
42+
* @psalm-suppress UnusedForeachValue
43+
*/
44+
public function isEmpty(): bool;
45+
46+
/**
47+
* Creates a new sequence by merging this one with the provided iterable. When the iterable is not a list, the provided values will override the existing items in case of a key collision.
48+
*
49+
* @template NewValue
50+
*
51+
* @param iterable<mixed, NewValue> $values
52+
*
53+
* @return self<TValue|NewValue>
54+
*
55+
* @psalm-mutation-free
56+
*/
57+
public function merge(iterable $values): self;
58+
59+
/**
60+
* Checks if the sequence contains the given key.
61+
*/
62+
public function hasKey(string|int $key): bool;
63+
64+
/**
65+
* Checks if the sequence contains the given value. The equality check is strict.
66+
*/
67+
public function hasValue(mixed $value): bool;
68+
69+
/**
70+
* Creates a filtered the sequence with the provided callback.
71+
*
72+
* @param callable(TValue, array-key):bool $callback
73+
*
74+
* @return self<TValue>
75+
*
76+
* @psalm-mutation-free
77+
*/
78+
public function filter(callable $callback): self;
79+
80+
/**
81+
* Maps the values of this sequence to a new one with the provided callback.
82+
*
83+
* @template ReturnType
84+
*
85+
* @param callable(TValue, array-key):ReturnType $callback
86+
*
87+
* @return self<ReturnType>
88+
*
89+
* @psalm-mutation-free
90+
*/
91+
public function map(callable $callback): self;
92+
93+
/**
94+
* Reduces this sequence with the given callback.
95+
*
96+
* @template TInitial
97+
*
98+
* @param TInitial|null $initial
99+
* @param callable(TInitial|null, TValue, array-key):TInitial $callback
100+
*
101+
* @return TInitial
102+
*/
103+
public function reduce(callable $callback, mixed $initial = null): mixed;
104+
105+
/**
106+
* Finds the position of the value within the sequence.
107+
*
108+
* @return false|array-key returns the key of the value if it is found, false otherwise
109+
*/
110+
public function find(mixed $value): false|string|int;
111+
112+
/**
113+
* Creates a reversed sequence.
114+
*
115+
* @return self<TValue>
116+
*
117+
* @psalm-mutation-free
118+
*/
119+
public function reversed(): self;
120+
121+
/**
122+
* Slices a new sequence starting from the given offset with a certain length.
123+
* If the length is null it will slice the entire remainder starting from the offset.
124+
*
125+
* @return self<TValue>
126+
*
127+
* @psalm-mutation-free
128+
*/
129+
public function slice(int $offset, ?int $length = null): self;
130+
131+
/**
132+
* Creates a sorted sequence. If the comparator is null it will use natural ordering.
133+
*
134+
* @param (callable(TValue, TValue):int)|null $comparator
135+
*
136+
* @return self<TValue>
137+
*
138+
* @psalm-mutation-free
139+
*/
140+
public function sorted(?callable $comparator = null): self;
141+
142+
/**
143+
* Creates a list from the arrays and objects in the sequence whose values corresponding with the provided key.
144+
*
145+
* @return CypherList<mixed>
146+
*
147+
* @psalm-mutation-free
148+
*/
149+
public function pluck(string|int $key): CypherList;
150+
151+
/**
152+
* Uses the values found at the provided key as the key for the new Map.
153+
*
154+
* @return CypherMap<mixed>
155+
*
156+
* @psalm-mutation-free
157+
*/
158+
public function keyBy(string|int $key): CypherMap;
159+
160+
/**
161+
* Joins the values within the sequence together with the provided glue. If the glue is null, it will be an empty string.
162+
*/
163+
public function join(?string $glue = null): string;
164+
165+
/**
166+
* Iterates over the sequence and applies the callable.
167+
*
168+
* @param callable(TValue, array-key):void $callable
169+
*
170+
* @return self<TValue>
171+
*/
172+
public function each(callable $callable): self;
173+
174+
/**
175+
* Returns the sequence as an array.
176+
*
177+
* @return array<array-key, TValue>
178+
*/
179+
public function toArray(): array;
180+
181+
/**
182+
* Returns the sequence as an array.
183+
*
184+
* @return array<array-key, TValue|array>
185+
*/
186+
public function toRecursiveArray(): array;
187+
188+
/**
189+
* @return Iterator<array-key, TValue>
190+
*/
191+
public function getGenerator(): Iterator;
192+
193+
/**
194+
* @return self<TValue>
195+
*/
196+
public function withCacheLimit(int $cacheLimit): self;
197+
198+
/**
199+
* Preload the lazy evaluation.
200+
*/
201+
public function preload(): void;
202+
203+
public function __serialize(): array;
204+
}

0 commit comments

Comments
 (0)