Skip to content

Commit b9ea524

Browse files
committed
fixed typings
1 parent 123697f commit b9ea524

File tree

6 files changed

+55
-34
lines changed

6 files changed

+55
-34
lines changed

src/Exception/RuntimeTypeException.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
<?php
2+
23
declare(strict_types=1);
34

5+
/*
6+
* This file is part of the Laudis Neo4j package.
7+
*
8+
* (c) Laudis technologies <http://laudis.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+
414
namespace Laudis\Neo4j\Exception;
515

6-
use RuntimeException;
7-
use Throwable;
816
use function get_debug_type;
9-
use function gettype;
17+
use RuntimeException;
1018

1119
final class RuntimeTypeException extends RuntimeException
1220
{

src/TypeCaster.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public static function toBool($value): ?bool
106106
public static function toClass($value, string $class): ?object
107107
{
108108
if (is_a($value, $class)) {
109+
/** @var T */
109110
return $value;
110111
}
111112

@@ -115,13 +116,17 @@ public static function toClass($value, string $class): ?object
115116
/**
116117
* @param mixed $value
117118
*
118-
* @pure
119+
* @return list<mixed>
120+
*
121+
* @psalm-external-mutation-free
119122
*/
120123
public static function toArray($value): ?array
121124
{
122125
if (is_iterable($value)) {
123126
$tbr = [];
127+
/** @var mixed $x */
124128
foreach ($value as $x) {
129+
/** @var mixed */
125130
$tbr[] = $x;
126131
}
127132

@@ -134,6 +139,8 @@ public static function toArray($value): ?array
134139
/**
135140
* @param mixed $value
136141
*
142+
* @return CypherList<mixed>|null
143+
*
137144
* @pure
138145
*/
139146
public static function toCypherList($value): ?CypherList
@@ -148,6 +155,8 @@ public static function toCypherList($value): ?CypherList
148155
/**
149156
* @param mixed $value
150157
*
158+
* @return CypherMap<mixed>|null
159+
*
151160
* @pure
152161
*/
153162
public static function toCypherMap($value): ?CypherMap

src/Types/ArrayList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
use function array_key_last;
1818
use function array_slice;
1919
use function is_int;
20+
use function is_iterable;
2021
use Laudis\Neo4j\Exception\RuntimeTypeException;
2122
use Laudis\Neo4j\TypeCaster;
2223
use OutOfBoundsException;
23-
use function is_iterable;
2424
use function sort;
2525
use function usort;
2626

@@ -201,6 +201,7 @@ public function getAsBool(int $key): bool
201201
*/
202202
public function getAsNull(int $key)
203203
{
204+
/** @psalm-suppress UnusedMethodCall */
204205
$this->get($key);
205206

206207
return TypeCaster::toNull();

src/Types/CypherList.php

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

1414
namespace Laudis\Neo4j\Types;
1515

16-
use function array_key_exists;
17-
use function array_key_last;
18-
use function array_slice;
19-
use function is_int;
2016
use Laudis\Neo4j\Exception\RuntimeTypeException;
2117
use Laudis\Neo4j\TypeCaster;
22-
use OutOfBoundsException;
23-
use function sort;
24-
use function usort;
2518

2619
/**
2720
* An immutable ordered sequence of items.

src/Types/CypherMap.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ final class CypherMap extends Map
3333
*
3434
* @return CypherMap<mixed>
3535
*/
36-
public function getAsCypherMap(int $key, $default = null): CypherMap
36+
public function getAsCypherMap(string $key, $default = null): CypherMap
3737
{
3838
if (func_num_args() === 1) {
3939
$value = $this->get($key);
4040
} else {
41+
/** @var mixed */
4142
$value = $this->get($key, $default);
4243
}
4344
$tbr = TypeCaster::toCypherMap($value);
@@ -53,11 +54,12 @@ public function getAsCypherMap(int $key, $default = null): CypherMap
5354
*
5455
* @return CypherList<mixed>
5556
*/
56-
public function getAsCypherList(int $key, $default = null): CypherList
57+
public function getAsCypherList(string $key, $default = null): CypherList
5758
{
5859
if (func_num_args() === 1) {
5960
$value = $this->get($key);
6061
} else {
62+
/** @var mixed */
6163
$value = $this->get($key, $default);
6264
}
6365
$tbr = TypeCaster::toCypherList($value);
@@ -71,7 +73,7 @@ public function getAsCypherList(int $key, $default = null): CypherList
7173
/**
7274
* @param mixed $default
7375
*/
74-
public function getAsDate(int $key, $default = null): Date
76+
public function getAsDate(string $key, $default = null): Date
7577
{
7678
if (func_num_args() === 1) {
7779
return $this->getAsObject($key, Date::class);
@@ -83,7 +85,7 @@ public function getAsDate(int $key, $default = null): Date
8385
/**
8486
* @param mixed $default
8587
*/
86-
public function getAsDateTime(int $key, $default = null): DateTime
88+
public function getAsDateTime(string $key, $default = null): DateTime
8789
{
8890
if (func_num_args() === 1) {
8991
return $this->getAsObject($key, DateTime::class);
@@ -95,7 +97,7 @@ public function getAsDateTime(int $key, $default = null): DateTime
9597
/**
9698
* @param mixed $default
9799
*/
98-
public function getAsDuration(int $key, $default = null): Duration
100+
public function getAsDuration(string $key, $default = null): Duration
99101
{
100102
if (func_num_args() === 1) {
101103
return $this->getAsObject($key, Duration::class);
@@ -107,7 +109,7 @@ public function getAsDuration(int $key, $default = null): Duration
107109
/**
108110
* @param mixed $default
109111
*/
110-
public function getAsLocalDateTime(int $key, $default = null): LocalDateTime
112+
public function getAsLocalDateTime(string $key, $default = null): LocalDateTime
111113
{
112114
if (func_num_args() === 1) {
113115
return $this->getAsObject($key, LocalDateTime::class);
@@ -119,7 +121,7 @@ public function getAsLocalDateTime(int $key, $default = null): LocalDateTime
119121
/**
120122
* @param mixed $default
121123
*/
122-
public function getAsLocalTime(int $key, $default = null): LocalTime
124+
public function getAsLocalTime(string $key, $default = null): LocalTime
123125
{
124126
if (func_num_args() === 1) {
125127
return $this->getAsObject($key, LocalTime::class);
@@ -131,7 +133,7 @@ public function getAsLocalTime(int $key, $default = null): LocalTime
131133
/**
132134
* @param mixed $default
133135
*/
134-
public function getAsTime(int $key, $default = null): Time
136+
public function getAsTime(string $key, $default = null): Time
135137
{
136138
if (func_num_args() === 1) {
137139
return $this->getAsObject($key, Time::class);
@@ -143,7 +145,7 @@ public function getAsTime(int $key, $default = null): Time
143145
/**
144146
* @param mixed $default
145147
*/
146-
public function getAsNode(int $key, $default = null): Node
148+
public function getAsNode(string $key, $default = null): Node
147149
{
148150
if (func_num_args() === 1) {
149151
return $this->getAsObject($key, Node::class);
@@ -155,7 +157,7 @@ public function getAsNode(int $key, $default = null): Node
155157
/**
156158
* @param mixed $default
157159
*/
158-
public function getAsRelationship(int $key, $default = null): Relationship
160+
public function getAsRelationship(string $key, $default = null): Relationship
159161
{
160162
if (func_num_args() === 1) {
161163
return $this->getAsObject($key, Relationship::class);
@@ -167,7 +169,7 @@ public function getAsRelationship(int $key, $default = null): Relationship
167169
/**
168170
* @param mixed $default
169171
*/
170-
public function getAsPath(int $key, $default = null): Path
172+
public function getAsPath(string $key, $default = null): Path
171173
{
172174
if (func_num_args() === 1) {
173175
return $this->getAsObject($key, Path::class);
@@ -179,7 +181,7 @@ public function getAsPath(int $key, $default = null): Path
179181
/**
180182
* @param mixed $default
181183
*/
182-
public function getAsCartesian3DPoint(int $key, $default = null): Cartesian3DPoint
184+
public function getAsCartesian3DPoint(string $key, $default = null): Cartesian3DPoint
183185
{
184186
if (func_num_args() === 1) {
185187
return $this->getAsObject($key, Cartesian3DPoint::class);
@@ -191,7 +193,7 @@ public function getAsCartesian3DPoint(int $key, $default = null): Cartesian3DPoi
191193
/**
192194
* @param mixed $default
193195
*/
194-
public function getAsCartesianPoint(int $key, $default = null): CartesianPoint
196+
public function getAsCartesianPoint(string $key, $default = null): CartesianPoint
195197
{
196198
if (func_num_args() === 1) {
197199
return $this->getAsObject($key, CartesianPoint::class);
@@ -203,7 +205,7 @@ public function getAsCartesianPoint(int $key, $default = null): CartesianPoint
203205
/**
204206
* @param mixed $default
205207
*/
206-
public function getAsWGS84Point(int $key, $default = null): WGS84Point
208+
public function getAsWGS84Point(string $key, $default = null): WGS84Point
207209
{
208210
if (func_num_args() === 1) {
209211
return $this->getAsObject($key, WGS84Point::class);
@@ -215,7 +217,7 @@ public function getAsWGS84Point(int $key, $default = null): WGS84Point
215217
/**
216218
* @param mixed $default
217219
*/
218-
public function getAsWGS843DPoint(int $key, $default = null): WGS843DPoint
220+
public function getAsWGS843DPoint(string $key, $default = null): WGS843DPoint
219221
{
220222
if (func_num_args() === 1) {
221223
return $this->getAsObject($key, WGS843DPoint::class);

src/Types/Map.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public function getAsString(string $key, $default = null): string
351351
if (func_num_args() === 1) {
352352
$value = $this->get($key);
353353
} else {
354+
/** @var mixed */
354355
$value = $this->get($key, $default);
355356
}
356357
$tbr = TypeCaster::toString($value);
@@ -369,6 +370,7 @@ public function getAsInt(string $key, $default): int
369370
if (func_num_args() === 1) {
370371
$value = $this->get($key);
371372
} else {
373+
/** @var mixed */
372374
$value = $this->get($key, $default);
373375
}
374376
$tbr = TypeCaster::toInt($value);
@@ -382,11 +384,12 @@ public function getAsInt(string $key, $default): int
382384
/**
383385
* @param mixed $default
384386
*/
385-
public function getAsFloat(int $key, $default = null): float
387+
public function getAsFloat(string $key, $default = null): float
386388
{
387389
if (func_num_args() === 1) {
388390
$value = $this->get($key);
389391
} else {
392+
/** @var mixed */
390393
$value = $this->get($key, $default);
391394
}
392395
$tbr = TypeCaster::toFloat($value);
@@ -400,11 +403,12 @@ public function getAsFloat(int $key, $default = null): float
400403
/**
401404
* @param mixed $default
402405
*/
403-
public function getAsBool(int $key, $default = null): bool
406+
public function getAsBool(string $key, $default = null): bool
404407
{
405408
if (func_num_args() === 1) {
406409
$value = $this->get($key);
407410
} else {
411+
/** @var mixed */
408412
$value = $this->get($key, $default);
409413
}
410414
$tbr = TypeCaster::toBool($value);
@@ -420,9 +424,10 @@ public function getAsBool(int $key, $default = null): bool
420424
*
421425
* @return null
422426
*/
423-
public function getAsNull(int $key, $default = null)
427+
public function getAsNull(string $key, $default = null)
424428
{
425429
if (func_num_args() === 1) {
430+
/** @psalm-suppress UnusedMethodCall */
426431
$this->get($key);
427432
}
428433

@@ -437,11 +442,12 @@ public function getAsNull(int $key, $default = null)
437442
*
438443
* @return U
439444
*/
440-
public function getAsObject(int $key, string $class, $default = null): object
445+
public function getAsObject(string $key, string $class, $default = null): object
441446
{
442447
if (func_num_args() === 1) {
443448
$value = $this->get($key);
444449
} else {
450+
/** @var mixed */
445451
$value = $this->get($key, $default);
446452
}
447453
$tbr = TypeCaster::toClass($value, $class);
@@ -457,11 +463,12 @@ public function getAsObject(int $key, string $class, $default = null): object
457463
*
458464
* @return Map<mixed>
459465
*/
460-
public function getAsMap(int $key, $default = null): Map
466+
public function getAsMap(string $key, $default = null): Map
461467
{
462468
if (func_num_args() === 1) {
463469
$value = $this->get($key);
464470
} else {
471+
/** @var mixed */
465472
$value = $this->get($key, $default);
466473
}
467474

@@ -475,13 +482,14 @@ public function getAsMap(int $key, $default = null): Map
475482
/**
476483
* @param mixed $default
477484
*
478-
* @return CypherList<mixed>
485+
* @return ArrayList<mixed>
479486
*/
480-
public function getAsArrayList(int $key, $default = null): ArrayList
487+
public function getAsArrayList(string $key, $default = null): ArrayList
481488
{
482489
if (func_num_args() === 1) {
483490
$value = $this->get($key);
484491
} else {
492+
/** @var mixed */
485493
$value = $this->get($key, $default);
486494
}
487495
if (!is_iterable($value)) {

0 commit comments

Comments
 (0)