Skip to content

Commit

Permalink
Merge pull request #72 from daniel-de-wit/update/laravel-9
Browse files Browse the repository at this point in the history
Add Laravel 9 and PHP 8.1 support
  • Loading branch information
daniel-de-wit authored Mar 6, 2022
2 parents 7cf017f + 631fc00 commit cdbd4b3
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0]
php: [8.1]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-fix-code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.0 ]
dependency-version: [ prefer-stable ]
os: [ubuntu-latest]
php: [8.1]
dependency-version: [prefer-stable]
env:
COMPOSER_NO_INTERACTION: 1

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Static Analysis

on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
static-analysis:
Expand All @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0]
php: [8.1]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Tests

on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
test:
Expand All @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4, 8.0]
php: [8.0, 8.1]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

$config = require __DIR__ . '/.php_cs.common.php';

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
Expand Down
4 changes: 3 additions & 1 deletion .php_cs.common.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@
'no_unused_imports' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => [
'elements' => ['arrays'],
],
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
Expand Down
2 changes: 1 addition & 1 deletion .php_cs.tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules($config)
->setRiskyAllowed(true)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Add [Laravel Sanctum](https://github.com/laravel/sanctum) support to [Lighthouse

## Requirements

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

## Installation
Expand Down
53 changes: 27 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
{
"name": "daniel-de-wit/lighthouse-sanctum",
"type": "library",
"description": "Laravel Sanctum support for Laravel Lighthouse.",
"license": "MIT",
"type": "library",
"keywords": [
"daniel-de-wit",
"laravel-sanctum",
"lighthouse",
"lighthouse-sanctum"
],
"homepage": "https://github.com/daniel-de-wit/lighthouse-sanctum",
"license": "MIT",
"authors": [
{
"name": "Daniel de Wit",
"email": "[email protected]",
"role": "Developer"
}
],
"homepage": "https://github.com/daniel-de-wit/lighthouse-sanctum",
"require": {
"php": "^7.4 || ^8.0",
"laravel/framework": "^8.36.2",
"laravel/sanctum": "^2.10",
"php": "^8.0.2",
"laravel/framework": "^9.0",
"laravel/sanctum": "^2.14",
"nuwave/lighthouse": "^5.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
"mockery/mockery": "^1.3.3",
"nunomaduro/larastan": "^0.7.2",
"orchestra/testbench": "^6.5",
"orchestra/testbench-core": "^v6.23.1",
"phpstan/phpstan-mockery": "^0.12.13",
"phpstan/phpstan-phpunit": "^0.12.18",
"friendsofphp/php-cs-fixer": "^3.0",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^1.0 || ^2.0",
"orchestra/testbench": "^6.0 || ^7.0",
"orchestra/testbench-core": "^6.26 || ^7.0",
"phpoption/phpoption": "^1.8",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"thecodingmachine/phpstan-safe-rule": "^1.0"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"DanielDeWit\\LighthouseSanctum\\Providers\\LighthouseSanctumServiceProvider"
]
}
"thecodingmachine/safe": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -54,11 +45,21 @@
"DanielDeWit\\LighthouseSanctum\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"DanielDeWit\\LighthouseSanctum\\Providers\\LighthouseSanctumServiceProvider"
]
}
},
"scripts": {
"analyze": "vendor/phpstan/phpstan/phpstan analyse",
"check-style": [
"php-cs-fixer fix --diff --diff-format=udiff --dry-run",
"php-cs-fixer fix --diff --diff-format=udiff --dry-run --config=.php_cs.tests.php"
"php-cs-fixer fix --diff --dry-run",
"php-cs-fixer fix --diff --dry-run --config=.php_cs.tests.php"
],
"coverage": "vendor/bin/phpunit",
"fix-style": [
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ includes:
- vendor/phpstan/phpstan-mockery/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon

parameters:
level: max
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
failOnRisky="true"
failOnWarning="true"
verbose="true"
convertDeprecationsToExceptions="false"
>
<testsuites>
<testsuite name="Integration">
Expand Down
12 changes: 9 additions & 3 deletions src/GraphQL/Mutations/ForgotPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ public function __construct(
/**
* @param mixed $_
* @param array<string, mixed> $args
* @return array<string, string|array>
* @return array<string, string>
* @throws Exception
*/
public function __invoke($_, array $args): array
{
if (isset($args['reset_password_url'])) {
$this->resetPasswordService->setResetPasswordUrl($args['reset_password_url']['url']);
/** @var array<string, string> $resetPasswordUrl */
$resetPasswordUrl = $args['reset_password_url'];

$this->resetPasswordService->setResetPasswordUrl($resetPasswordUrl['url']);
}

$this->passwordBroker->sendResetLink([
'email' => $args['email'],
]);

/** @var string $message */
$message = $this->translator->get('An email has been sent');

return [
'status' => 'EMAIL_SENT',
'message' => $this->translator->get('An email has been sent'),
'message' => $message,
];
}
}
7 changes: 5 additions & 2 deletions src/GraphQL/Mutations/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(AuthFactory $authFactory, Translator $translator)
/**
* @param mixed $_
* @param array<string, mixed> $args
* @return array<string, string|array>
* @return array<string, string>
* @throws Exception
*/
public function __invoke($_, array $args): array
Expand All @@ -43,9 +43,12 @@ public function __invoke($_, array $args): array
$personalAccessToken = $user->currentAccessToken();
$personalAccessToken->delete();

/** @var string $message */
$message = $this->translator->get('Your session has been terminated');

return [
'status' => 'TOKEN_REVOKED',
'message' => $this->translator->get('Your session has been terminated'),
'message' => $message,
];
}

Expand Down
5 changes: 4 additions & 1 deletion src/GraphQL/Mutations/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public function __invoke($_, array $args): array

if ($user instanceof MustVerifyEmail) {
if (isset($args['verification_url'])) {
$this->emailVerificationService->setVerificationUrl($args['verification_url']['url']);
/** @var array<string, string> $verificationUrl */
$verificationUrl = $args['verification_url'];

$this->emailVerificationService->setVerificationUrl($verificationUrl['url']);
}

$user->sendEmailVerificationNotification();
Expand Down
5 changes: 4 additions & 1 deletion src/GraphQL/Mutations/ResendEmailVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public function __invoke($_, array $args): array

if ($user && $user instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) {
if (isset($args['verification_url'])) {
$this->emailVerificationService->setVerificationUrl($args['verification_url']['url']);
/** @var array<string, string> $verificationUrl */
$verificationUrl = $args['verification_url'];

$this->emailVerificationService->setVerificationUrl($verificationUrl['url']);
}

$user->sendEmailVerificationNotification();
Expand Down
10 changes: 7 additions & 3 deletions src/GraphQL/Mutations/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
* @param array<string, mixed> $args
* @param GraphQLContext $context
* @param ResolveInfo $resolveInfo
* @return array<string, string|array>
* @return array<string, string>
* @throws Exception
*/
public function __invoke($_, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): array
Expand All @@ -45,19 +45,23 @@ public function __invoke($_, array $args, GraphQLContext $context, ResolveInfo $
'password_confirmation',
]);

/** @var string $response */
$response = $this->passwordBroker->reset($credentials, function (Authenticatable $user, string $password) {
$this->resetPasswordService->resetPassword($user, $password);
});

/** @var string $message */
$message = $this->translator->get($response);

if ($response === PasswordBroker::PASSWORD_RESET) {
return [
'status' => 'PASSWORD_RESET',
'message' => $this->translator->get($response),
'message' => $message,
];
}

throw new GraphQLValidationException(
$this->translator->get($response),
$message,
$this->getInvalidField($response),
$resolveInfo,
);
Expand Down
4 changes: 3 additions & 1 deletion src/GraphQL/Mutations/UpdatePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(AuthFactory $authFactory, Hasher $hasher, Translator

/**
* @param mixed $_
* @param array<string, mixed> $args
* @param array<string, string> $args
* @param GraphQLContext $context
* @param ResolveInfo $resolveInfo
* @return array<string, string>
Expand Down Expand Up @@ -66,6 +66,7 @@ public function __invoke($_, array $args, GraphQLContext $context, ResolveInfo $
protected function currentPasswordMustBeTheSame(Authenticatable $user, string $currentPassword): void
{
if (! $this->hasher->check($currentPassword, $user->getAuthPassword())) {
/** @var string $message */
$message = $this->translator->get('validation.same', [
'attribute' => 'current_password',
'other' => 'user password',
Expand All @@ -83,6 +84,7 @@ protected function currentPasswordMustBeTheSame(Authenticatable $user, string $c
protected function newPasswordMustBeDifferent(Authenticatable $user, string $newPassword): void
{
if ($this->hasher->check($newPassword, $user->getAuthPassword())) {
/** @var string $message */
$message = $this->translator->get('validation.different', [
'attribute' => 'password',
'other' => 'user password',
Expand Down
16 changes: 11 additions & 5 deletions src/Providers/LighthouseSanctumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@ public function register(): void
/** @var Config $config */
$config = $container->make(Config::class);

return new SignatureService($config->get('app.key'));
/** @var string $appKey */
$appKey = $config->get('app.key');

return new SignatureService($appKey);
});

$this->app->singleton(EmailVerificationServiceInterface::class, function (Container $container) {
/** @var Config $config */
$config = $container->make(Config::class);

return new EmailVerificationService(
$container->make(SignatureServiceInterface::class),
$config->get('auth.verification.expire', 60),
);
/** @var SignatureServiceInterface $signatureService */
$signatureService = $container->make(SignatureServiceInterface::class);

/** @var int $expiresIn */
$expiresIn = $config->get('auth.verification.expire', 60);

return new EmailVerificationService($signatureService, $expiresIn);
});
}

Expand Down
1 change: 1 addition & 0 deletions src/Traits/CreatesUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ abstract protected function getConfig(): Config;

protected function createUserProvider(): UserProvider
{
/** @var string $provider */
$provider = $this->getConfig()->get('lighthouse-sanctum.provider');

$userProvider = $this->getAuthManager()->createUserProvider($provider);
Expand Down
Loading

0 comments on commit cdbd4b3

Please sign in to comment.