Skip to content

Commit b9465e3

Browse files
authored
Merge pull request #34 from etsvThor/upgrade/php8.4
Add support for php8.4
2 parents 95a3b31 + 2f38d26 commit b9465e3

19 files changed

+343
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ _ide_helper_models.php
1919
.phpstorm.meta.php
2020
.*.swp
2121
composer.lock
22+
.php-cs-fixer.cache

.php-cs-fixer.php

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
6+
7+
$rules = [
8+
'array_indentation' => true,
9+
'array_syntax' => ['syntax' => 'short'],
10+
'binary_operator_spaces' => [
11+
'default' => 'single_space',
12+
],
13+
'blank_line_after_namespace' => true,
14+
'blank_line_after_opening_tag' => true,
15+
'blank_line_before_statement' => [
16+
'statements' => ['return'],
17+
],
18+
'braces' => true,
19+
'cast_spaces' => true,
20+
'class_attributes_separation' => [
21+
'elements' => [
22+
'const' => 'only_if_meta',
23+
'method' => 'one',
24+
'property' => 'one',
25+
'trait_import' => 'none',
26+
],
27+
],
28+
'class_definition' => [
29+
'multi_line_extends_each_single_line' => true,
30+
'single_item_single_line' => true,
31+
'single_line' => true,
32+
],
33+
'concat_space' => [
34+
'spacing' => 'none',
35+
],
36+
'constant_case' => ['case' => 'lower'],
37+
'declare_equal_normalize' => true,
38+
'elseif' => true,
39+
'encoding' => true,
40+
'full_opening_tag' => true,
41+
'fully_qualified_strict_types' => false,
42+
// added by Shift
43+
'function_declaration' => true,
44+
'function_typehint_space' => true,
45+
'general_phpdoc_tag_rename' => true,
46+
'heredoc_to_nowdoc' => true,
47+
'include' => true,
48+
'increment_style' => ['style' => 'post'],
49+
'indentation_type' => true,
50+
'linebreak_after_opening_tag' => true,
51+
'line_ending' => true,
52+
'lowercase_cast' => true,
53+
'lowercase_keywords' => true,
54+
'lowercase_static_reference' => true,
55+
'magic_method_casing' => true,
56+
'magic_constant_casing' => true,
57+
'method_argument_space' => [
58+
'on_multiline' => 'ignore',
59+
],
60+
'multiline_whitespace_before_semicolons' => [
61+
'strategy' => 'no_multi_line',
62+
],
63+
'native_function_casing' => true,
64+
'no_alias_functions' => true,
65+
'no_extra_blank_lines' => [
66+
'tokens' => [
67+
'extra',
68+
'throw',
69+
'use',
70+
'switch',
71+
'case',
72+
'default',
73+
],
74+
],
75+
'no_blank_lines_after_class_opening' => true,
76+
'no_blank_lines_after_phpdoc' => true,
77+
'no_closing_tag' => true,
78+
'no_empty_phpdoc' => true,
79+
'no_empty_statement' => true,
80+
'no_leading_import_slash' => true,
81+
'no_leading_namespace_whitespace' => true,
82+
'no_mixed_echo_print' => [
83+
'use' => 'echo',
84+
],
85+
'no_multiline_whitespace_around_double_arrow' => true,
86+
'no_short_bool_cast' => true,
87+
'no_singleline_whitespace_before_semicolons' => true,
88+
'no_spaces_after_function_name' => true,
89+
'no_spaces_around_offset' => [
90+
'positions' => [
91+
'inside',
92+
'outside',
93+
],
94+
],
95+
'no_spaces_inside_parenthesis' => true,
96+
'no_trailing_comma_in_list_call' => true,
97+
'no_trailing_comma_in_singleline_array' => true,
98+
'no_trailing_whitespace' => true,
99+
'no_trailing_whitespace_in_comment' => true,
100+
'no_unneeded_control_parentheses' => [
101+
'statements' => [
102+
'break',
103+
'clone',
104+
'continue',
105+
'echo_print',
106+
'return',
107+
'switch_case',
108+
'yield',
109+
],
110+
],
111+
'no_unreachable_default_argument_value' => true,
112+
'no_useless_return' => true,
113+
'no_whitespace_before_comma_in_array' => true,
114+
'no_whitespace_in_blank_line' => true,
115+
'normalize_index_brace' => true,
116+
'not_operator_with_successor_space' => true,
117+
'object_operator_without_whitespace' => true,
118+
'ordered_imports' => [
119+
'sort_algorithm' => 'alpha',
120+
'imports_order' => [
121+
'class',
122+
'function',
123+
'const',
124+
],
125+
],
126+
'psr_autoloading' => true,
127+
'phpdoc_indent' => true,
128+
'phpdoc_inline_tag_normalizer' => true,
129+
'phpdoc_no_access' => true,
130+
'phpdoc_no_package' => true,
131+
'phpdoc_no_useless_inheritdoc' => true,
132+
'phpdoc_scalar' => true,
133+
'phpdoc_single_line_var_spacing' => true,
134+
'phpdoc_summary' => false,
135+
'phpdoc_to_comment' => false,
136+
// override to preserve user preference
137+
'phpdoc_tag_type' => true,
138+
'phpdoc_trim' => true,
139+
'phpdoc_types' => true,
140+
'phpdoc_var_without_name' => true,
141+
'self_accessor' => true,
142+
'short_scalar_cast' => true,
143+
'simplified_null_return' => false,
144+
'single_blank_line_at_eof' => true,
145+
'single_blank_line_before_namespace' => true,
146+
'single_class_element_per_statement' => [
147+
'elements' => [
148+
'const',
149+
'property',
150+
],
151+
],
152+
'single_import_per_statement' => true,
153+
'single_line_after_imports' => true,
154+
'single_line_comment_style' => [
155+
'comment_types' => ['hash'],
156+
],
157+
'single_quote' => true,
158+
'space_after_semicolon' => true,
159+
'standardize_not_equals' => true,
160+
'switch_case_semicolon_to_colon' => true,
161+
'switch_case_space' => true,
162+
'ternary_operator_spaces' => true,
163+
'trailing_comma_in_multiline' => [
164+
'elements' => [
165+
'arrays',
166+
'parameters',
167+
],
168+
],
169+
'trim_array_spaces' => true,
170+
'types_spaces' => [
171+
'space' => 'single',
172+
],
173+
'unary_operator_spaces' => true,
174+
'visibility_required' => [
175+
'elements' => [
176+
'method',
177+
'property',
178+
'const',
179+
],
180+
],
181+
'whitespace_after_comma_in_array' => true,
182+
'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
183+
'simplified_if_return' => true,
184+
'method_chaining_indentation' => true,
185+
186+
'AdamWojs/phpdoc_force_fqcn_fixer' => true,
187+
];
188+
189+
$finder = Finder::create()
190+
->in([
191+
__DIR__.'/src',
192+
__DIR__.'/config',
193+
__DIR__.'/routes',
194+
])
195+
->name('*.php')
196+
->notName('*.blade.php')
197+
->ignoreDotFiles(true)
198+
->ignoreVCS(true);
199+
200+
/** @var \PhpCsFixer\ConfigInterface&\PhpCsFixer\ParallelAwareConfigInterface $config */
201+
$config = (new Config)
202+
->setFinder($finder)
203+
->setRules($rules)
204+
->setRiskyAllowed(true)
205+
->setUsingCache(true)
206+
->registerCustomFixers([
207+
new \AdamWojs\PhpCsFixerPhpdocForceFQCN\Fixer\Phpdoc\ForceFQCNFixer(),
208+
]);
209+
210+
if (php_uname('s') === 'Darwin' && php_uname('m') === 'arm64') {
211+
// Probably running apple m1/m2, in which parallel is bugged.
212+
return $config;
213+
}
214+
215+
return $config->setParallelConfig(ParallelConfigFactory::detect());

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"homepage": "https://github.com/etsvthor/laravel-bifrost-bridge",
1515
"require": {
16-
"php": "~8.1.0 | ~8.2.0 | ~8.3.0",
16+
"php": "~8.1.0 | ~8.2.0 | ~8.3.0 | ~8.4.0",
1717
"spatie/laravel-permission": "^4.0 | ^5.0 | ^6.0",
1818
"laravel/framework": "^10.0 | ^11.4.1 | ^12.19.3",
1919
"laravel/socialite": "^5.1",
@@ -35,5 +35,10 @@
3535
"EtsvThor\\BifrostBridge\\BifrostBridgeServiceProvider"
3636
]
3737
}
38+
},
39+
"require-dev": {
40+
"phpstan/phpstan": "^2.1",
41+
"friendsofphp/php-cs-fixer": "^3.85",
42+
"adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0"
3843
}
3944
}

config/bifrost.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@
5454

5555
// Service configuration
5656
'service' => [
57-
'host' => env('BIFROST_HOST', 'https://bifrost.thor.edu'),
58-
'client_id' => env('BIFROST_CLIENT_ID'),
57+
'host' => env('BIFROST_HOST', 'https://bifrost.thor.edu'),
58+
'client_id' => env('BIFROST_CLIENT_ID'),
5959
'client_secret' => env('BIFROST_CLIENT_SECRET'),
60-
'redirect' => env('BIFROST_REDIRECT_URL', '/login/callback'),
60+
'redirect' => env('BIFROST_REDIRECT_URL', '/login/callback'),
6161

6262
'authorize_uri' => 'oauth/authorize',
63-
'token_uri' => 'oauth/token',
64-
'userinfo_uri' => 'api/user',
63+
'token_uri' => 'oauth/token',
64+
'userinfo_uri' => 'api/user',
6565

66-
'intended' => 'login',
66+
'intended' => 'login',
6767

68-
'scopes' => [],
68+
'scopes' => [],
6969

70-
'guzzle' => [],
70+
'guzzle' => [],
7171
],
7272
];

phpstan.neon.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- vendor/nesbot/carbon/extension.neon
3+
4+
parameters:
5+
6+
paths:
7+
- src/
8+
- routes/
9+
- config/
10+
11+
level: 5
12+

routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Route;
43
use EtsvThor\BifrostBridge\Http\Controllers\LoginController;
54
use EtsvThor\BifrostBridge\Http\Controllers\WebhookController;
5+
use Illuminate\Support\Facades\Route;
66

77
Route::get('login', [LoginController::class, 'redirect'])->name('login');
88
Route::get('login/callback', [LoginController::class, 'callback']);

src/BifrostBridge.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace EtsvThor\BifrostBridge;
44

55
use EtsvThor\BifrostBridge\Data\BifrostUserData;
6-
use Spatie\Permission\Models\Role;
7-
use Illuminate\Database\Eloquent\Model;
8-
use Spatie\Permission\PermissionRegistrar;
9-
use Illuminate\Database\Eloquent\SoftDeletes;
106
use Illuminate\Contracts\Auth\MustVerifyEmail;
117
use Illuminate\Database\Eloquent\Builder;
8+
use Illuminate\Database\Eloquent\Model;
9+
use Illuminate\Database\Eloquent\SoftDeletes;
10+
use Spatie\Permission\Models\Role;
11+
use Spatie\Permission\PermissionRegistrar;
1212

1313
class BifrostBridge
1414
{
@@ -62,20 +62,20 @@ public static function memberIdKey(): ?string
6262
}
6363

6464
// Helpers
65-
public static function isSoftDeletable(Model $model = null): bool
65+
public static function isSoftDeletable(Model | null $model = null): bool
6666
{
6767
return in_array(SoftDeletes::class, class_uses_recursive($model ?? static::getUserClass())) === true;
6868
}
6969

70-
public static function isVerifyingEmail(Model $model = null): bool
70+
public static function isVerifyingEmail(Model | null $model = null): bool
7171
{
72-
return (($model ?? static::getUserClass()) instanceof MustVerifyEmail);
72+
return ($model ?? static::getUserClass()) instanceof MustVerifyEmail;
7373
}
7474

75-
public static function applyWithTrashed(Model $model = null): Builder
75+
public static function applyWithTrashed(Model | null $model = null): Builder
7676
{
7777
return static::isSoftDeletable($model ??= static::getUserClass())
78-
? $model->withTrashed()
78+
? $model->withTrashed() // @phpstan-ignore method.notFound
7979
: $model->query();
8080
}
8181
}

src/BifrostBridgeServiceProvider.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace EtsvThor\BifrostBridge;
34

45
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
@@ -47,12 +48,12 @@ protected function bootRoutes(): void
4748
{
4849
// Register routes
4950
Route::group($this->routeConfiguration(), function () {
50-
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
51+
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
5152
});
5253

5354
if (
5455
version_compare($this->app->version(), '11.0', '>=')
55-
&& method_exists(VerifyCsrfToken::class, 'except')
56+
&& method_exists(VerifyCsrfToken::class, 'except') // @phpstan-ignore function.alreadyNarrowedType
5657
) {
5758
VerifyCsrfToken::except([
5859
'webhooks/bifrost',
@@ -71,16 +72,17 @@ protected function routeConfiguration(): array
7172
protected function bootMacros(): void
7273
{
7374
if (! Request::hasMacro('verifySignature')) {
74-
Request::macro('verifySignature', function(string $key, string $header = 'X-Signature', string $algo = 'sha256'): bool {
75+
Request::macro('verifySignature', function (string $key, string $header = 'X-Signature', string $algo = 'sha256'): bool {
7576
/** @var \Illuminate\Http\Request $this */
7677

77-
return ($this->hasHeader($header) && $this->header($header) === hash_hmac($algo, $this->getContent(), $key));
78+
return $this->hasHeader($header) && $this->header($header) === hash_hmac($algo, $this->getContent(), $key);
7879
});
7980
}
8081
}
8182

8283
protected function bootSocialite(): void
8384
{
85+
/** @var \Laravel\Socialite\SocialiteManager */
8486
$socialite = $this->app->make(SocialiteFactory::class);
8587

8688
$socialite->extend(

0 commit comments

Comments
 (0)