Skip to content

Commit 589c216

Browse files
committed
Enable rector/type-perfect for stricter type checking
But ignore unavoidable interface returns on public APIs
1 parent 4be2466 commit 589c216

13 files changed

Lines changed: 43 additions & 15 deletions

File tree

UPGRADE-8.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ The following list has been generated with [roave/backward-compatibility-check](
5050
[BC] CHANGED: The parameter $clearTextPassword of Kreait\Firebase\Request\EditUserTrait#withClearTextPassword() changed from Stringable|string to string
5151
[BC] CHANGED: The parameter $code of Kreait\Firebase\Exception\Database\TransactionFailed#__construct() changed from int to a non-contravariant Throwable|null
5252
[BC] CHANGED: The parameter $code of Kreait\Firebase\Exception\Database\UnsupportedQuery#__construct() changed from int to a non-contravariant Throwable|null
53+
[BC] CHANGED: The parameter $config of Kreait\Firebase\Messaging\CloudMessage#withAndroidConfig() changed from no type to a non-contravariant Kreait\Firebase\Messaging\AndroidConfig|array
54+
[BC] CHANGED: The parameter $config of Kreait\Firebase\Messaging\CloudMessage#withApnsConfig() changed from no type to a non-contravariant Kreait\Firebase\Messaging\ApnsConfig|array
5355
[BC] CHANGED: The parameter $email of Kreait\Firebase\Contract\Auth#createUserWithEmailAndPassword() changed from Stringable|string to a non-contravariant string
5456
[BC] CHANGED: The parameter $email of Kreait\Firebase\Contract\Auth#createUserWithEmailAndPassword() changed from Stringable|string to string
5557
[BC] CHANGED: The parameter $email of Kreait\Firebase\Contract\Auth#getEmailActionLink() changed from Stringable|string to a non-contravariant string
@@ -147,6 +149,9 @@ The following list has been generated with [roave/backward-compatibility-check](
147149
[BC] CHANGED: The parameter $url of Kreait\Firebase\Request\EditUserTrait#withPhotoUrl() changed from Stringable|string to string
148150
[BC] CHANGED: The parameter $user of Kreait\Firebase\Contract\Auth#signInAsUser() changed from Kreait\Firebase\Auth\UserRecord|Stringable|string to Kreait\Firebase\Auth\UserRecord|string
149151
[BC] CHANGED: The parameter $user of Kreait\Firebase\Contract\Auth#signInAsUser() changed from Kreait\Firebase\Auth\UserRecord|Stringable|string to a non-contravariant Kreait\Firebase\Auth\UserRecord|string
152+
[BC] CHANGED: The parameter $value of Kreait\Firebase\Messaging\ApnsConfig#withDataField() changed from mixed to a non-contravariant string
153+
[BC] CHANGED: The parameter $value of Kreait\Firebase\RemoteConfig\ConditionalValue#withValue() changed from no type to Kreait\Firebase\RemoteConfig\ParameterValue|array|string
154+
[BC] CHANGED: The parameter $value of Kreait\Firebase\RemoteConfig\ConditionalValue#withValue() changed from no type to a non-contravariant Kreait\Firebase\RemoteConfig\ParameterValue|array|string
150155
[BC] CHANGED: The return type of Kreait\Firebase\RemoteConfig\ConditionalValue#value() changed from no type to string|array
151156
[BC] CHANGED: The return type of Kreait\Firebase\RemoteConfig\TagColor#__toString() changed from no type to string
152157
[BC] REMOVED: Class Kreait\Firebase\Contract\DynamicLinks has been deleted

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ parameters:
3838
reportPossiblyNonexistentConstantArrayOffset: true
3939
# reportPossiblyNonexistentGeneralArrayOffset: true
4040
reportAnyTypeWideningInVarTag: true
41+
42+
type_perfect:
43+
no_mixed_property: true
44+
no_mixed_caller: true
45+
null_over_false: true
46+
narrow_param: false
47+
narrow_return: true
4148
includes:
4249
- vendor/cuyz/valinor/qa/PHPStan/valinor-phpstan-configuration.php
4350
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

src/Firebase/Auth/CreateActionLink/GuzzleApiClientHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Kreait\Firebase\Auth\ProjectAwareAuthResourceUrlBuilder;
1414
use Kreait\Firebase\Auth\TenantAwareAuthResourceUrlBuilder;
1515
use Psr\Http\Client\ClientExceptionInterface;
16-
use Psr\Http\Message\RequestInterface;
1716

1817
use function array_filter;
1918

@@ -68,7 +67,7 @@ public function handle(CreateActionLink $action): string
6867
return (string) $actionCode;
6968
}
7069

71-
private function createRequest(CreateActionLink $action): RequestInterface
70+
private function createRequest(CreateActionLink $action): Request
7271
{
7372
$data = [
7473
'requestType' => $action->type(),

src/Firebase/Auth/CreateSessionCookie/GuzzleApiClientHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Kreait\Firebase\Auth\ProjectAwareAuthResourceUrlBuilder;
1414
use Kreait\Firebase\Auth\TenantAwareAuthResourceUrlBuilder;
1515
use Psr\Http\Client\ClientExceptionInterface;
16-
use Psr\Http\Message\RequestInterface;
1716

1817
use function array_filter;
1918

@@ -63,7 +62,7 @@ public function handle(CreateSessionCookie $action): string
6362
throw new FailedToCreateSessionCookie($action, $response, 'The response did not contain a session cookie');
6463
}
6564

66-
private function createRequest(CreateSessionCookie $action): RequestInterface
65+
private function createRequest(CreateSessionCookie $action): Request
6766
{
6867
$data = [
6968
'idToken' => $action->idToken(),

src/Firebase/Auth/SendActionLink/GuzzleApiClientHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Kreait\Firebase\Auth\SendActionLink;
1313
use Kreait\Firebase\Auth\TenantAwareAuthResourceUrlBuilder;
1414
use Psr\Http\Client\ClientExceptionInterface;
15-
use Psr\Http\Message\RequestInterface;
1615

1716
use function array_filter;
1817

@@ -50,7 +49,7 @@ public function handle(SendActionLink $action): void
5049
}
5150
}
5251

53-
private function createRequest(SendActionLink $action): RequestInterface
52+
private function createRequest(SendActionLink $action): Request
5453
{
5554
$data = [
5655
'requestType' => $action->type(),

src/Firebase/Auth/SignIn/GuzzleHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Kreait\Firebase\Auth\SignInWithRefreshToken;
2222
use Kreait\Firebase\Util;
2323
use Psr\Http\Client\ClientExceptionInterface;
24-
use Psr\Http\Message\RequestInterface;
2524
use UnexpectedValueException;
2625

2726
use function http_build_query;
@@ -77,7 +76,7 @@ public function handle(SignIn $action): SignInResult
7776
return SignInResult::fromData($data);
7877
}
7978

80-
private function createApiRequest(SignIn $action): RequestInterface
79+
private function createApiRequest(SignIn $action): Request
8180
{
8281
return match (true) {
8382
$action instanceof SignInAnonymously => $this->anonymous($action),

src/Firebase/Factory.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ public function withClock(object $clock): self
303303
return $factory;
304304
}
305305

306+
/**
307+
* @phpstan-ignore typePerfect.narrowReturnObjectType
308+
*/
306309
public function createAppCheck(): Contract\AppCheck
307310
{
308311
$projectId = $this->getProjectId();
@@ -336,6 +339,9 @@ public function createAppCheck(): Contract\AppCheck
336339
);
337340
}
338341

342+
/**
343+
* @phpstan-ignore typePerfect.narrowReturnObjectType
344+
*/
339345
public function createAuth(): Contract\Auth
340346
{
341347
$projectId = $this->getProjectId();
@@ -358,6 +364,9 @@ public function createAuth(): Contract\Auth
358364
return new Auth($authApiClient, $customTokenGenerator, $idTokenVerifier, $sessionCookieVerifier, $this->clock);
359365
}
360366

367+
/**
368+
* @phpstan-ignore typePerfect.narrowReturnObjectType
369+
*/
361370
public function createDatabase(): Contract\Database
362371
{
363372
$middlewares = array_filter([
@@ -379,6 +388,9 @@ public function createDatabase(): Contract\Database
379388
);
380389
}
381390

391+
/**
392+
* @phpstan-ignore typePerfect.narrowReturnObjectType
393+
*/
382394
public function createRemoteConfig(): Contract\RemoteConfig
383395
{
384396
$http = $this->createApiClient([
@@ -394,6 +406,9 @@ public function createRemoteConfig(): Contract\RemoteConfig
394406
);
395407
}
396408

409+
/**
410+
* @phpstan-ignore typePerfect.narrowReturnObjectType
411+
*/
397412
public function createMessaging(): Contract\Messaging
398413
{
399414
$projectId = $this->getProjectId();
@@ -437,6 +452,9 @@ public function createFirestore(?string $databaseName = null): Contract\Firestor
437452
return Firestore::fromConfig($config);
438453
}
439454

455+
/**
456+
* @phpstan-ignore typePerfect.narrowReturnObjectType
457+
*/
440458
public function createStorage(): Contract\Storage
441459
{
442460
try {

src/Firebase/Firestore.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ private function __construct(private FirestoreClient $client)
1919

2020
/**
2121
* @param array<non-empty-string, mixed> $config
22+
*
23+
* @phpstan-ignore typePerfect.narrowReturnObjectType
2224
*/
2325
public static function fromConfig(array $config): Contract\Firestore
2426
{

src/Firebase/Messaging.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private function messageHasTarget(Message $message): bool
271271
|| array_key_exists(MessageTarget::TOPIC, $check);
272272
}
273273

274-
private function withChangedTarget(Message $message, string $target, string $value): Message
274+
private function withChangedTarget(Message $message, string $target, string $value): RawMessageFromArray
275275
{
276276
$message = Json::decode(Json::encode($message), true);
277277

src/Firebase/Messaging/ApnsConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function withApsField(string $key, mixed $value): self
105105
/**
106106
* @param non-empty-string $name
107107
*/
108-
public function withDataField(string $name, mixed $value): self
108+
public function withDataField(string $name, string $value): self
109109
{
110110
if ($name === 'aps') {
111111
throw new InvalidArgument('"aps" is a reserved field name');

0 commit comments

Comments
 (0)