Skip to content

Commit b18ae49

Browse files
Make PHPStan happy
1 parent 3f616af commit b18ae49

36 files changed

Lines changed: 51 additions & 331 deletions

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
"ext-ctype": "*"
5151
},
5252
"require-dev": {
53-
"phpunit/phpunit": "~9.0",
54-
"infection/infection": "^0.25.5",
53+
"phpunit/phpunit": "^10.0",
54+
"infection/infection": "^0.29",
5555
"friendsofphp/php-cs-fixer": "^3.0",
5656
"rregeer/phpunit-coverage-check": "^0.3.1",
57-
"phpstan/phpstan": "^1.8"
57+
"phpstan/phpstan": "^2.0"
5858
},
5959
"autoload": {
6060
"files": [

phpstan.neon.dist

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
paths:
33
- src
4-
level: 7
5-
treatPhpDocTypesAsCertain: false
4+
level: 9
5+
treatPhpDocTypesAsCertain: false
6+
ignoreErrors:
7+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
8+
- "#Function [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
9+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type iterable#"
10+
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ return type has no value type specified in iterable type array#"

src/Clauses/CallClause.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace WikibaseSolutions\CypherDSL\Clauses;
1111

1212
use WikibaseSolutions\CypherDSL\Expressions\Variable;
13+
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
1314
use WikibaseSolutions\CypherDSL\Query;
1415
use WikibaseSolutions\CypherDSL\Utils\CastUtils;
1516

@@ -53,7 +54,7 @@ public function withSubQuery(Query $subQuery): self
5354
*
5455
* @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-correlated-importing
5556
*/
56-
public function addWithVariable(...$variables): self
57+
public function addWithVariable(Pattern|Variable|string ...$variables): self
5758
{
5859
$res = [];
5960

src/Clauses/CallProcedureClause.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class CallProcedureClause extends Clause
3131
private ?Procedure $procedure = null;
3232

3333
/**
34-
* @var Alias[]|Variable[]|(Alias|Variable)[] The result fields that are yielded
34+
* @var Alias[]|(Alias|Variable)[]|Variable[] The result fields that are yielded
3535
*/
3636
private array $yields = [];
3737

src/Expressions/Literals/List_.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function __construct(array $expressions = [])
4545
/**
4646
* Add one or more expressions to the list.
4747
*
48-
* @param AnyType|array|bool|float|int|Pattern|string ...$expressions
49-
*
5048
* @return $this
5149
*/
5250
public function addExpression(AnyType|bool|float|int|array|Pattern|string ...$expressions): self

src/Expressions/Literals/Literal.php

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use WikibaseSolutions\CypherDSL\Expressions\Procedures\Point;
2121
use WikibaseSolutions\CypherDSL\Expressions\Procedures\Procedure;
2222
use WikibaseSolutions\CypherDSL\Expressions\Procedures\Time;
23+
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
24+
use WikibaseSolutions\CypherDSL\Types\AnyType;
2325
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType;
2426
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\StringType;
2527

@@ -34,7 +36,7 @@ final class Literal
3436
* Creates a new literal from the given value. This function automatically constructs the appropriate
3537
* class based on the type of the value given.
3638
*
37-
* @param mixed $literal The literal to construct
39+
* @param array|bool|float|int|string|Stringable $literal The literal to construct
3840
*
3941
* @throws TypeError when the type could not be deduced
4042
*/
@@ -49,7 +51,6 @@ public static function literal(string|bool|int|float|array|Stringable $literal):
4951
}
5052

5153
if (is_int($literal)) {
52-
// @phpstan-ignore-next-line
5354
return self::integer($literal);
5455
}
5556

@@ -61,11 +62,7 @@ public static function literal(string|bool|int|float|array|Stringable $literal):
6162
return array_is_list($literal) ? self::list($literal) : self::map($literal);
6263
}
6364

64-
if (is_object($literal) && method_exists($literal, '__toString')) {
65-
return self::string($literal->__toString());
66-
}
67-
68-
throw new TypeError("The literal type " . get_debug_type($literal) . " is not supported by Cypher");
65+
return self::string($literal->__toString());
6966
}
7067

7168
/**
@@ -84,7 +81,6 @@ public static function decimal(float|int $value): Float_|Integer
8481
*/
8582
public static function number(float|int $value): Float_|Integer
8683
{
87-
// @phpstan-ignore-next-line PHPStan does not work well with classes named "Integer"
8884
return is_int($value) ? self::integer($value) : self::float($value);
8985
}
9086

@@ -126,8 +122,6 @@ public static function float(float $value): Float_
126122

127123
/**
128124
* Creates a new list literal.
129-
*
130-
* @param mixed[] $value
131125
*/
132126
public static function list(iterable $value): List_
133127
{
@@ -150,8 +144,6 @@ public static function map(array $value): Map
150144
* Retrieves the current Date value, optionally for a different time zone. In reality, this function just returns
151145
* a call to the "date()" function.
152146
*
153-
* @param null|string|StringType $timezone
154-
*
155147
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-current Corresponding documentation on Neo4j.com
156148
*/
157149
public static function date(StringType|string|null $timezone = null): Date
@@ -166,9 +158,6 @@ public static function date(StringType|string|null $timezone = null): Date
166158
/**
167159
* Creates a date from the given year, month and day.
168160
*
169-
* @param null|int|NumeralType $month
170-
* @param null|int|NumeralType $day
171-
*
172161
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-calendar Corresponding documentation on Neo4j.com
173162
*/
174163
public static function dateYMD(NumeralType|int $year, NumeralType|int|null $month = null, NumeralType|int|null $day = null): Date
@@ -187,9 +176,6 @@ public static function dateYMD(NumeralType|int $year, NumeralType|int|null $mont
187176
/**
188177
* Creates a date from the given year, week and weekday.
189178
*
190-
* @param null|int|NumeralType $week
191-
* @param null|int|NumeralType $weekday
192-
*
193179
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-date-week Corresponding documentation on Neo4j.com
194180
*/
195181
public static function dateYWD(NumeralType|int $year, NumeralType|int|null $week = null, NumeralType|int|null $weekday = null): Date
@@ -219,8 +205,6 @@ public static function dateString(StringType|string $date): Date
219205
* Retrieves the current DateTime value, optionally for a different time zone. In reality, this
220206
* function just returns a call to the "datetime()" function.
221207
*
222-
* @param null|string|StringType $timezone
223-
*
224208
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-current Corresponding documentation on Neo4j.com
225209
*/
226210
public static function dateTime(StringType|string|null $timezone = null): DateTime
@@ -235,16 +219,6 @@ public static function dateTime(StringType|string|null $timezone = null): DateTi
235219
/**
236220
* Creates a date from the given year, month, day and time values.
237221
*
238-
* @param null|int|NumeralType $month
239-
* @param null|int|NumeralType $day
240-
* @param null|int|NumeralType $hour
241-
* @param null|int|NumeralType $minute
242-
* @param null|int|NumeralType $second
243-
* @param null|int|NumeralType $millisecond
244-
* @param null|int|NumeralType $microsecond
245-
* @param null|int|NumeralType $nanosecond
246-
* @param null|string|StringType $timezone
247-
*
248222
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-calendar Corresponding documentation on Neo4j.com
249223
*/
250224
public static function dateTimeYMD(
@@ -280,16 +254,6 @@ public static function dateTimeYMD(
280254
/**
281255
* Creates a datetime with the specified year, week, dayOfWeek, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
282256
*
283-
* @param null|int|NumeralType $week
284-
* @param null|int|NumeralType $dayOfWeek
285-
* @param null|int|NumeralType $hour
286-
* @param null|int|NumeralType $minute
287-
* @param null|int|NumeralType $second
288-
* @param null|int|NumeralType $millisecond
289-
* @param null|int|NumeralType $microsecond
290-
* @param null|int|NumeralType $nanosecond
291-
* @param null|string|StringType $timezone
292-
*
293257
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-week Corresponding documentation on Neo4j.com
294258
*/
295259
public static function dateTimeYWD(
@@ -325,16 +289,6 @@ public static function dateTimeYWD(
325289
/**
326290
* Creates a datetime with the specified year, quarter, dayOfQuarter, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
327291
*
328-
* @param null|int|NumeralType $quarter
329-
* @param null|int|NumeralType $dayOfQuarter
330-
* @param null|int|NumeralType $hour
331-
* @param null|int|NumeralType $minute
332-
* @param null|int|NumeralType $second
333-
* @param null|int|NumeralType $millisecond
334-
* @param null|int|NumeralType $microsecond
335-
* @param null|int|NumeralType $nanosecond
336-
* @param null|string|StringType $timezone
337-
*
338292
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-quarter Corresponding documentation on Neo4j.com
339293
*/
340294
public static function dateTimeYQD(
@@ -370,15 +324,6 @@ public static function dateTimeYQD(
370324
/**
371325
* Creates a datetime with the specified year, ordinalDay, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
372326
*
373-
* @param null|int|NumeralType $ordinalDay
374-
* @param null|int|NumeralType $hour
375-
* @param null|int|NumeralType $minute
376-
* @param null|int|NumeralType $second
377-
* @param null|int|NumeralType $millisecond
378-
* @param null|int|NumeralType $microsecond
379-
* @param null|int|NumeralType $nanosecond
380-
* @param null|string|StringType $timezone
381-
*
382327
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-datetime-ordinal Corresponding documentation on Neo4j.com
383328
*/
384329
public static function dateTimeYD(
@@ -420,8 +365,6 @@ public static function dateTimeString(StringType|string $dateString): DateTime
420365
/**
421366
* Creates the current localDateTime value.
422367
*
423-
* @param null|string|StringType $timezone
424-
*
425368
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-current Corresponding documentation on Neo4j.com
426369
*/
427370
public static function localDateTime(StringType|string|null $timezone = null): LocalDateTime
@@ -436,15 +379,6 @@ public static function localDateTime(StringType|string|null $timezone = null): L
436379
/**
437380
* Creates a LocalDateTime value with specified year, month, day and time props.
438381
*
439-
* @param null|int|NumeralType $month
440-
* @param null|int|NumeralType $day
441-
* @param null|int|NumeralType $hour
442-
* @param null|int|NumeralType $minute
443-
* @param null|int|NumeralType $second
444-
* @param null|int|NumeralType $millisecond
445-
* @param null|int|NumeralType $microsecond
446-
* @param null|int|NumeralType $nanosecond
447-
*
448382
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-calendar Corresponding documentation on Neo4j.com
449383
*/
450384
public static function localDateTimeYMD(
@@ -479,15 +413,6 @@ public static function localDateTimeYMD(
479413
* Creates a LocalDateTime value with the specified year, week, dayOfWeek, hour, minute,
480414
* second, millisecond, microsecond and nanosecond component value.
481415
*
482-
* @param null|int|NumeralType $week
483-
* @param null|int|NumeralType $dayOfWeek
484-
* @param null|int|NumeralType $hour
485-
* @param null|int|NumeralType $minute
486-
* @param null|int|NumeralType $second
487-
* @param null|int|NumeralType $millisecond
488-
* @param null|int|NumeralType $microsecond
489-
* @param null|int|NumeralType $nanosecond
490-
*
491416
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-week Corresponding documentation on Neo4j.com
492417
*/
493418
public static function localDateTimeYWD(
@@ -521,15 +446,6 @@ public static function localDateTimeYWD(
521446
/**
522447
* Creates a LocalDateTime value with the specified year, quarter, dayOfQuarter, hour, minute, second, millisecond, microsecond and nanosecond component values.
523448
*
524-
* @param null|int|NumeralType $quarter
525-
* @param null|int|NumeralType $dayOfQuarter
526-
* @param null|int|NumeralType $hour
527-
* @param null|int|NumeralType $minute
528-
* @param null|int|NumeralType $second
529-
* @param null|int|NumeralType $millisecond
530-
* @param null|int|NumeralType $microsecond
531-
* @param null|int|NumeralType $nanosecond
532-
*
533449
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-quarter Corresponding documentation on Neo4j.com
534450
*/
535451
public static function localDateTimeYQD(
@@ -563,14 +479,6 @@ public static function localDateTimeYQD(
563479
/**
564480
* Creates a LocalDateTime value with the specified year, ordinalDay, hour, minute, second, millisecond, microsecond and nanosecond component values.
565481
*
566-
* @param null|int|NumeralType $ordinalDay
567-
* @param null|int|NumeralType $hour
568-
* @param null|int|NumeralType $minute
569-
* @param null|int|NumeralType $second
570-
* @param null|int|NumeralType $millisecond
571-
* @param null|int|NumeralType $microsecond
572-
* @param null|int|NumeralType $nanosecond
573-
*
574482
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localdatetime-ordinal Corresponding documentation on Neo4j.com
575483
*/
576484
public static function localDateTimeYD(
@@ -612,8 +520,6 @@ public static function localDateTimeString(StringType|string $localDateTimeStrin
612520
/**
613521
* Creates the current LocalTime value.
614522
*
615-
* @param null|string|StringType $timezone
616-
*
617523
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-current Corresponding documentation on Neo4j.com
618524
*/
619525
public static function localTimeCurrent(StringType|string|null $timezone = null): LocalTime
@@ -628,12 +534,6 @@ public static function localTimeCurrent(StringType|string|null $timezone = null)
628534
/**
629535
* Creates a LocalTime value with the specified hour, minute, second, millisecond, microsecond and nanosecond component values.
630536
*
631-
* @param null|int|NumeralType $minute
632-
* @param null|int|NumeralType $second
633-
* @param null|int|NumeralType $millisecond
634-
* @param null|int|NumeralType $microsecond
635-
* @param null|int|NumeralType $nanosecond
636-
*
637537
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-localtime-create Corresponding documentation on Neo4j.com
638538
*/
639539
public static function localTime(
@@ -669,8 +569,6 @@ public static function localTimeString(StringType|string $localTimeString): Loca
669569
/**
670570
* Creates the current Time value.
671571
*
672-
* @param null|string|StringType $timezone
673-
*
674572
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-current Corresponding documentation on Neo4j.com
675573
*/
676574
public static function time(StringType|string|null $timezone = null): Time
@@ -685,13 +583,6 @@ public static function time(StringType|string|null $timezone = null): Time
685583
/**
686584
* Creates a Time value with the specified hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
687585
*
688-
* @param null|int|NumeralType $minute
689-
* @param null|int|NumeralType $second
690-
* @param null|int|NumeralType $millisecond
691-
* @param null|int|NumeralType $microsecond
692-
* @param null|int|NumeralType $nanosecond
693-
* @param null|string|StringType $timezone
694-
*
695586
* @see https://neo4j.com/docs/cypher-manual/current/functions/temporal/#functions-time-create Corresponding documentation on Neo4j.com
696587
*/
697588
public static function timeHMS(
@@ -701,7 +592,7 @@ public static function timeHMS(
701592
NumeralType|int|null $millisecond = null,
702593
NumeralType|int|null $microsecond = null,
703594
NumeralType|int|null $nanosecond = null,
704-
NumeralType|int|null $timezone = null
595+
StringType|string|null $timezone = null
705596
): Time {
706597
return Procedure::time(
707598
self::makeTemporalMap(
@@ -795,6 +686,8 @@ private function __construct()
795686

796687
/**
797688
* Prepares the variables to be used by temporal (i.e. time-like) CYPHER-functions.
689+
*
690+
* @return (AnyType|array|bool|float|int|Pattern|string)[]
798691
*/
799692
private static function makeTemporalMap(array $variables): array
800693
{

src/Expressions/Literals/Map.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace WikibaseSolutions\CypherDSL\Expressions\Literals;
1111

12+
use Stringable;
13+
use WikibaseSolutions\CypherDSL\Patterns\Pattern;
1214
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\CompositeTypeTraits\MapTypeTrait;
1315
use WikibaseSolutions\CypherDSL\Types\AnyType;
1416
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\MapType;
@@ -46,12 +48,12 @@ public function __construct(array $elements = [])
4648
/**
4749
* Adds an element for the given name with the given value. Overrides the element if the $key already exists.
4850
*
49-
* @param string $key The name/label for the element
50-
* @param mixed $value The value of the element
51+
* @param string $key The name/label for the element
52+
* @param AnyType|array|bool|float|int|Pattern|string|Stringable $value The value of the element
5153
*
5254
* @return $this
5355
*/
54-
public function add(string $key, mixed $value): self
56+
public function add(string $key, AnyType|Pattern|Stringable|bool|float|int|array|string $value): self
5557
{
5658
$this->elements[$key] = CastUtils::toAnyType($value);
5759

src/Patterns/Node.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public function withLabels(array $labels): self
5757
/**
5858
* Adds one or more labels to this node.
5959
*
60-
* @param string ...$label
61-
*
6260
* @return $this
6361
*/
6462
public function addLabel(string ...$label): self

0 commit comments

Comments
 (0)