Skip to content

Commit

Permalink
Fix phpstan issues (#78)
Browse files Browse the repository at this point in the history
* Update README.md

* Fix: call_user_func expects callable, Closure given

* Fix Closure(mixed) type issues

* Formatting

* Remove phpstan ignore

* Add Lighthouse guard configuration section to README.md

* Fix: call_user_func expects callable, Closure given

* Fix Closure(mixed) type issues

* Formatting

* Remove phpstan ignore

* Max phpstan level without ignoring errors

* normalize composer.json

* Ignore files for dist checkout

* Ignore files for dist checkout

* Update README.md
  • Loading branch information
daniel-de-wit authored Jun 23, 2022
1 parent a2618ab commit ac7f617
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 17 deletions.
20 changes: 13 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/stubs export-ignore
/phpstan.neon export-ignore
/.php_cs.tests.php export-ignore
/.php_cs.common.php export-ignore
/.php-cs-fixer.dist.php export-ignore
/.coveralls.yml export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
.phpunit.cache
.php_cs.cache
.php_cs.tests.cache
phpunit.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add [Laravel Sanctum](https://github.com/laravel/sanctum) support to [Lighthouse

- [laravel/laravel:^9.0](https://github.com/laravel/laravel)
- [laravel/sanctum:^2.0](https://github.com/laravel/sanctum)
- [nuwave/lighthouse:^5.5](https://github.com/nuwave/lighthouse)
- [nuwave/lighthouse:^5.55.1](https://github.com/nuwave/lighthouse)

## Installation

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"php": "^8.0.2",
"laravel/framework": "^9.0",
"laravel/sanctum": "^2.14",
"nuwave/lighthouse": "^5.5"
"nuwave/lighthouse": "^5.55.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
Expand Down Expand Up @@ -56,6 +56,9 @@
}
},
"scripts": {
"post-autoload-dump": [
"@php ./vendor/bin/testbench package:discover --ansi"
],
"analyze": "vendor/phpstan/phpstan/phpstan analyse",
"check-style": [
"php-cs-fixer fix --diff --dry-run",
Expand Down
10 changes: 5 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ parameters:
paths:
- src
- tests
ignoreErrors:
-
message: '#Parameter \#1 \$(function|callback) of function call_user_func expects callable\(\): mixed, Closure\|null given\.#'
path: tests
- '#Call to an undefined method Illuminate\\Testing\\TestResponse::assertGraphQLErrorMessage\(\).#'
stubFiles:
- vendor/nuwave/lighthouse/_ide_helper.php
- stubs/Illuminate/Auth/Notifications/ResetPassword.stub
- stubs/Illuminate/Auth/Notifications/Notification.stub
- stubs/Illuminate/Contracts/Auth/CanResetPassword.stub
1 change: 0 additions & 1 deletion src/Services/ResetPasswordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function transformUrl(CanResetPassword $notifiable, string $token, string

public function setResetPasswordUrl(string $url): void
{
/** @phpstan-ignore-next-line */
ResetPasswordNotification::createUrlUsing(function (CanResetPassword $notifiable, string $token) use ($url): string {
return $this->transformUrl($notifiable, $token, $url);
});
Expand Down
7 changes: 7 additions & 0 deletions stubs/Illuminate/Auth/Notifications/Notification.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Illuminate\Notifications;

class Notification
{
}
19 changes: 19 additions & 0 deletions stubs/Illuminate/Auth/Notifications/ResetPassword.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Illuminate\Auth\Notifications;

use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Notifications\Notification;

class ResetPassword extends Notification
{
/**
* Set a callback that should be used when creating the reset password button URL.
*
* @param \Closure(CanResetPassword, string): string $callback
* @return void
*/
public static function createUrlUsing($callback)
{
}
}
7 changes: 7 additions & 0 deletions stubs/Illuminate/Contracts/Auth/CanResetPassword.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Illuminate\Contracts\Auth;

interface CanResetPassword
{
}
3 changes: 2 additions & 1 deletion tests/Integration/GraphQL/Mutations/ForgotPasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function it_sends_a_reset_password_notification(): void
]);

Notification::assertSentTo($user, function (ResetPassword $notification) use ($user) {
/** @phpstan-ignore-next-line */
static::assertIsCallable($notification::$createUrlCallback);

$url = call_user_func($notification::$createUrlCallback, $user, $notification->token);

return $url === "https://my-front-end.com/[email protected]&token={$notification->token}";
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/GraphQL/Mutations/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function it_sends_an_email_verification_notification(): void
$user = UserMustVerifyEmail::first();

Notification::assertSentTo($user, function (VerifyEmail $notification) use ($user) {
static::assertIsCallable($notification::$createUrlCallback);

$url = call_user_func($notification::$createUrlCallback, $user);

/** @var int|string $id */
Expand Down Expand Up @@ -151,6 +153,8 @@ public function it_sends_a_signed_email_verification_notification(): void
$user = UserMustVerifyEmail::first();

Notification::assertSentTo($user, function (VerifyEmail $notification) use ($user) {
static::assertIsCallable($notification::$createUrlCallback);

$url = call_user_func($notification::$createUrlCallback, $user);

/** @var int|string $id */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function it_resends_an_email_verification_notification(): void
static::assertSame('EMAIL_SENT', $response->json('data.resendEmailVerification.status'));

Notification::assertSentTo($user, function (VerifyEmail $notification) use ($user) {
static::assertIsCallable($notification::$createUrlCallback);

$url = call_user_func($notification::$createUrlCallback, $user);

$hash = sha1('[email protected]');
Expand Down Expand Up @@ -98,6 +100,8 @@ public function it_resends_a_signed_email_verification_notification(): void
static::assertSame('EMAIL_SENT', $response->json('data.resendEmailVerification.status'));

Notification::assertSentTo($user, function (VerifyEmail $notification) use ($user) {
static::assertIsCallable($notification::$createUrlCallback);

$url = call_user_func($notification::$createUrlCallback, $user);

$hash = sha1('[email protected]');
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/Services/EmailVerificationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function it_sets_the_verification_url(): void

$this->service->setVerificationUrl('https://mysite.com/verify-email/__ID__/__HASH__');

static::assertIsCallable(VerifyEmail::$createUrlCallback);

$url = call_user_func(VerifyEmail::$createUrlCallback, $user);

static::assertSame('https://mysite.com/verify-email/12345/' . sha1('[email protected]'), $url);
Expand All @@ -102,6 +104,8 @@ public function it_sets_the_signed_verification_url(): void

$this->service->setVerificationUrl('https://mysite.com/verify-email/__ID__/__HASH__/__EXPIRES__/__SIGNATURE__');

static::assertIsCallable(VerifyEmail::$createUrlCallback);

$url = call_user_func(VerifyEmail::$createUrlCallback, $user);

$signature = hash_hmac('sha256', serialize([
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Services/ResetPasswordServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function it_sets_the_reset_password_url(): void

$this->service->setResetPasswordUrl('https://mysite.com/reset-password/__EMAIL__/__TOKEN__');

/** @phpstan-ignore-next-line */
static::assertIsCallable(ResetPassword::$createUrlCallback);

$url = call_user_func(ResetPassword::$createUrlCallback, $user, $token);

static::assertSame('https://mysite.com/reset-password/[email protected]/token123', $url);
Expand Down

0 comments on commit ac7f617

Please sign in to comment.