Skip to content

Commit daf5632

Browse files
authored
upgrade to phpstan 2 (#15)
1 parent b97d77c commit daf5632

File tree

18 files changed

+36
-22
lines changed

18 files changed

+36
-22
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// Update 'VARIANT' to pick an Alpine version: 3.12, 3.13, 3.14, 3.15
88
"args": { "VARIANT": "3.14" }
99
},
10+
"runArgs": [
11+
"--security-opt=label=disable"
12+
],
1013
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind",
1114
"workspaceFolder": "/app",
1215
"remoteEnv": {

.docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ COPY --from=composer:2.8 /usr/bin/composer /usr/bin/composer
1515

1616
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
1717
bash /tmp/library-scripts/dev.sh "${USERNAME}"
18+
RUN docker-php-ext-install zip && docker-php-ext-enable zip
1819

1920
RUN mkdir /app && chown ${USERNAME}: /app
2021

.docker/dev.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
6565
libicu[0-9][0-9] \
6666
liblttng-ust[0-9] \
6767
libstdc++6 \
68+
libzip-dev \
6869
zlib1g \
6970
locales \
7071
init-system-helpers"

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
"php": "^8.2",
2727
"squizlabs/php_codesniffer": "^4.0",
2828
"slevomat/coding-standard": "^8.0",
29-
"phpstan/phpstan": "^1.12",
29+
"phpstan/phpstan": "^2.0",
3030
"phpstan/extension-installer": "^1.1",
31-
"phpstan/phpstan-strict-rules": "^1.1",
31+
"phpstan/phpstan-strict-rules": "^2.0",
3232
"phpunit/phpunit": "^11.3||^12.0",
3333
"texthtml/doctest": "^0.3.0"
3434
},

examples/Integer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TH\VOIdentity\Tests\Cloning;
44

55
use TH\VOIdentity\Identity;
6-
use PHPUnit\Framework\TestCase;
76

87
/**
98
* ```php

examples/Money.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TH\VOIdentity\Tests\Cloning;
44

55
use TH\VOIdentity\Identity;
6-
use PHPUnit\Framework\TestCase;
76

87
/**
98
* ```php
@@ -33,11 +32,16 @@ protected function __construct(
3332
}
3433

3534
public static function of(int|float $value, string $currency): self {
35+
// @phpstan-ignore argument.type,argument.type
3636
return self::ofMinor((int) ($value * 100), $currency);
3737
}
3838

39+
/**
40+
* @param int<1,max> $n
41+
*/
3942
public function dividedBy(int $n): self
4043
{
44+
// @phpstan-ignore argument.type,argument.type
4145
return self::ofMinor($this->cents / $n, $this->currency);
4246
}
4347
}

examples/TsRange.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TH\VOIdentity\Tests\Cloning;
44

55
use TH\VOIdentity\Identity;
6-
use PHPUnit\Framework\TestCase;
76

87
/**
98
* ```php
@@ -31,7 +30,11 @@ protected function __construct(
3130
) {
3231
}
3332

33+
/**
34+
* @throws \DateMalformedStringException
35+
*/
3436
public function extendBy(string $relativeTime): self {
37+
// @phpstan-ignore argument.type,argument.type
3538
return self::of($this->start, $this->end->modify($relativeTime));
3639
}
3740
}

examples/UserID.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace TH\VOIdentity\Tests\Cloning;
44

55
use TH\VOIdentity\Identity;
6-
use PHPUnit\Framework\TestCase;
76

87
/**
98
* ```php

phpstan.neon.dist

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
parameters:
2-
level: 9
3-
paths:
4-
- src
5-
exceptions:
6-
check:
7-
missingCheckedExceptionInThrows: true
8-
tooWideThrowType: true
2+
level: 9
3+
paths:
4+
- src
5+
- examples
6+
exceptions:
7+
check:
8+
missingCheckedExceptionInThrows: true
9+
tooWideThrowType: true
10+
ignoreErrors:
11+
-
12+
identifier: property.onlyWritten
13+
path: examples/

src/Identity.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ private function __construct() {}
1414
* @param array<mixed> $args
1515
*/
1616
final public static function of(mixed ...$args): self {
17+
// @phpstan-ignore argument.type
1718
$constructor = static fn () => new self(...$args);
1819

1920
return self::resolve($constructor, self::inputIdentity(...$args));
2021
}
2122

2223
/**
23-
* @param self|callable():self $ref
24+
* @param callable():self $ref
2425
* @phpstan-param array-key|null $key
2526
*/
2627
final protected static function resolve(callable $ref, int|string|null $key): self {
@@ -33,6 +34,7 @@ final protected static function resolve(callable $ref, int|string|null $key): se
3334
static $mem = [];
3435

3536
if (\array_key_exists($key, $mem)) {
37+
// @phpstan-ignore return.type
3638
return $mem[$key]->get();
3739
}
3840

@@ -64,13 +66,17 @@ protected static function inputIdentity(mixed ...$args): int|string|null {
6466
return null;
6567
}
6668

69+
/**
70+
* @throws \LogicException
71+
*/
6772
final public function __clone(): never
6873
{
6974
throw new \LogicException('Value Object ' . static::class . ' using ' . Identity::class . ' can\'t be cloned');
7075
}
7176

7277
/**
7378
* @param array<mixed> $data
79+
* @throws \LogicException
7480
*/
7581
final public function __unserialize(array $data): never
7682
{
@@ -88,6 +94,7 @@ final public function __unserialize(array $data): never
8894
*/
8995
public static function __set_state(array $data): self
9096
{
97+
// @phpstan-ignore argument.type
9198
return self::of(...$data);
9299
}
93100
}

0 commit comments

Comments
 (0)