Skip to content

Commit

Permalink
[3.x] PHP 9.4 support (#102)
Browse files Browse the repository at this point in the history
* PHP 8.4 support

* Apply fixes from StyleCI

[ci skip] [skip ci]

* Should fix static analysis

* Should fix static analysis 2

---------

Co-authored-by: Italo <[email protected]>
  • Loading branch information
DarkGhostHunter and DarkGhostHunter authored Jan 29, 2025
1 parent d1fd316 commit d0f127f
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 43 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
/tests export-ignore
/.editorconfig export-ignore
/.styleci.yml export-ignore
/composer.lock export-ignore
/composer.lock export-ignore
/phpstan.neon export-ignore
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4
laravel-constraint:
- 10.*
- 11.*
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"require-dev": {
"ext-sodium": "*",
"orchestra/testbench": "8.*|9.*"
"orchestra/testbench": "8.*|9.*",
"livewire/livewire": "3.*"
},
"suggest": {
"paragonie/sodium_compat": "To enable EdDSA 25519 keys from authenticators, if `ext-sodium` is unavailable."
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
parameters:
ignoreErrors:
- '#Trait Laragear\\WebAuthn\\WebAuthnAuthentication is used zero times and is not analysed\.#'
Empty file.
2 changes: 1 addition & 1 deletion src/Assertion/Validator/AssertionValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
/**
* Create a new Assertion Validation instance from a WebAuthn request data.
*/
public static function fromRequest(Request $request = null): static
public static function fromRequest(?Request $request = null): static
{
// @phpstan-ignore-next-line
return new static(new JsonTransport(($request ?? app('request'))->only(static::REQUEST_KEYS)));
Expand Down
2 changes: 1 addition & 1 deletion src/Assertion/Validator/Pipes/CheckPublicKeySignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function retrieveBinaryVerifiable(JsonTransport $request): string
$verifiable = ByteBuffer::decodeBase64Url($request->get('response.authenticatorData')).
hash('sha256', ByteBuffer::decodeBase64Url($request->get('response.clientDataJSON')), true);

return $verifiable
return $verifiable // @phpstan-ignore-line
?: throw AssertionException::make('Authenticator Data or Client Data JSON are empty or malformed.');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Attestation/AuthenticatorData.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ protected static function readAttestData(string $binary, int &$endOffset): objec
$length = unpack('nlength', substr($binary, 53, 2))['length'];

// Set end offset.
$endOffset = 55 + $length;
$endOffset = 55 + $length; // @phpstan-ignore-line

return (object) [
'aaguid' => substr($binary, 37, 16),
Expand All @@ -395,7 +395,7 @@ protected static function readAttestData(string $binary, int &$endOffset): objec
*/
protected static function readCredentialPublicKey(string $binary, int $offset, int &$endOffset): object
{
$enc = CborDecoder::decodePortion($binary, $offset, $endOffset);
$enc = CborDecoder::decodePortion($binary, $offset, $endOffset); // @phpstan-ignore-line

// COSE key-encoded elliptic curve public key in EC2 format
$publicKey = (object) [
Expand Down
2 changes: 1 addition & 1 deletion src/Attestation/Validator/AttestationValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
/**
* Create a new Attestation Creation instance from a request and a user.
*/
public static function fromRequest(Request $request = null, WebAuthnAuthenticatable $user = null): static
public static function fromRequest(?Request $request = null, ?WebAuthnAuthenticatable $user = null): static
{
// @phpstan-ignore-next-line
return new static($user, new JsonTransport(($request ?? app('request'))->only(static::REQUEST_KEYS)));
Expand Down
1 change: 1 addition & 0 deletions src/Auth/WebAuthnUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected function validateWebAuthn(WebAuthnAuthenticatable $user, array $creden
*/
public function rehashPasswordIfRequired(UserContract $user, array $credentials, bool $force = false): void
{
// @phpstan-ignore-next-line
if (! $this->isSignedChallenge($credentials) && method_exists(get_parent_class($this), 'rehashPasswordIfRequired')) {
parent::rehashPasswordIfRequired($user, $credentials, $force);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ByteBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function hashNotEqual(self|string $buffer): bool
/**
* Returns a certain portion of these bytes.
*/
public function getBytes(int $offset = 0, int $length = null): string
public function getBytes(int $offset = 0, ?int $length = null): string
{
$length ??= $this->dataLength;

Expand Down
2 changes: 1 addition & 1 deletion src/CborDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function decode(ByteBuffer|string $encoded): ByteBuffer|array|bool
*
* @throws \Laragear\WebAuthn\Exceptions\DataException
*/
public static function decodePortion(ByteBuffer|string $bufOrBin, int $startOffset, ?int &$endOffset = null): ByteBuffer|array|bool|float|int|string|null
public static function decodePortion(ByteBuffer|string $bufOrBin, int $startOffset, ?int &$endOffset = null): ByteBuffer|array|bool|float|int|string|null // @phpstan-ignore-line
{
$buf = $bufOrBin instanceof ByteBuffer ? $bufOrBin : new ByteBuffer($bufOrBin);

Expand Down
4 changes: 0 additions & 4 deletions src/Contracts/WebAuthnAuthenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public function makeWebAuthnCredential(array $properties): WebAuthnCredential;

/**
* Returns a queryable relationship for its WebAuthn Credentials.
*
* @phpstan-ignore-next-line
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany|\Laragear\WebAuthn\Models\WebAuthnCredential
*/
public function webAuthnCredentials(): MorphMany;
}
12 changes: 3 additions & 9 deletions src/Http/Requests/AssertedRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ public function hasRemember(): bool

/**
* Logs in the user for this assertion request.
*
* @param string|null $guard
*
* @phpstan-ignore-next-line
*
* @return \Laragear\WebAuthn\Contracts\WebAuthnAuthenticatable|\Illuminate\Contracts\Auth\Authenticatable|null
*/
public function login(
string $guard = null,
bool $remember = null,
?string $guard = null,
?bool $remember = null,
bool $destroySession = false,
callable|array $callbacks = null
callable|array|null $callbacks = null
): ?WebAuthnAuthenticatable {
/** @var \Illuminate\Contracts\Auth\StatefulGuard $auth */
$auth = auth()->guard($guard);
Expand Down
2 changes: 1 addition & 1 deletion src/JsonTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function set(string $key, mixed $value): void
/**
* Retrieves a value from the underlying JSON array.
*/
public function get(string $key, string|int $default = null): mixed
public function get(string $key, string|int|null $default = null): mixed
{
return Arr::get($this->json, $key, $default);
}
Expand Down
34 changes: 16 additions & 18 deletions src/Models/WebAuthnCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/**
* @mixin \Illuminate\Database\Eloquent\Builder
*
* @method \Illuminate\Database\Eloquent\Builder|\static newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\static query()
* @method \Illuminate\Database\Eloquent\Builder|static newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|static query()
* @method static \Laragear\WebAuthn\Models\WebAuthnCredential make(array $attributes = [])
* @method static \Laragear\WebAuthn\Models\WebAuthnCredential create(array $attributes = [])
* @method static \Laragear\WebAuthn\Models\WebAuthnCredential forceCreate(array $attributes)
Expand All @@ -27,20 +27,20 @@
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstOrNew(array $attributes = [], array $values = [])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstOrFail($columns = ['*'])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstOrCreate(array $attributes, array $values = [])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstOr($columns = ['*'], \Closure $callback = null)
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstOr($columns = ['*'], \Closure|null $callback = null)
* @method \Laragear\WebAuthn\Models\WebAuthnCredential firstWhere($column, $operator = null, $value = null, $boolean = 'and')
* @method \Laragear\WebAuthn\Models\WebAuthnCredential updateOrCreate(array $attributes, array $values = [])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential createOrFirst(array $attributes, array $values = [])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential sole($columns = ['*'])
* @method \Laragear\WebAuthn\Models\WebAuthnCredential findOrNew($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, \static>|\static[]|\static|null find($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, \static>|\static[]|\static findOrFail($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, \static>|\static[]|\static findOr($id, $columns = ['*'], \Closure $callback = null)
* @method \Illuminate\Database\Eloquent\Collection<int, \static>|\static[] findMany($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, \static>|\static[] fromQuery($query, $bindings = [])
* @method \Illuminate\Support\LazyCollection<int, \static>|\static[] lazy(int $chunkSize = 1000)
* @method \Illuminate\Support\LazyCollection<int, \static>|\static[] lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
* @method \Illuminate\Support\LazyCollection<int, \static>|\static[] lazyByIdDesc(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
* @method \Illuminate\Database\Eloquent\Collection<int, static>|static[]|static|null find($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, static>|static[]|static findOrFail($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, static>|static[]|static findOr($id, $columns = ['*'], \Closure|null $callback = null)
* @method \Illuminate\Database\Eloquent\Collection<int, static>|static[] findMany($id, $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, static>|static[] fromQuery($query, $bindings = [])
* @method \Illuminate\Support\LazyCollection<int, static>|static[] lazy(int $chunkSize = 1000)
* @method \Illuminate\Support\LazyCollection<int, static>|static[] lazyById(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
* @method \Illuminate\Support\LazyCollection<int, static>|static[] lazyByIdDesc(int $chunkSize = 1000, string|null $column = null, string|null $alias = null)
*
* @property-read string $id
* @property-read string $user_id
Expand All @@ -59,8 +59,8 @@
* @property-read \Illuminate\Support\Carbon $created_at
* @property-read \Laragear\WebAuthn\Contracts\WebAuthnAuthenticatable $authenticatable
*
* @method \Illuminate\Database\Eloquent\Builder|\static whereEnabled()
* @method \Illuminate\Database\Eloquent\Builder|\static whereDisabled()
* @method \Illuminate\Database\Eloquent\Builder|static whereEnabled()
* @method \Illuminate\Database\Eloquent\Builder|static whereDisabled()
*/
class WebAuthnCredential extends Model
{
Expand Down Expand Up @@ -101,13 +101,11 @@ class WebAuthnCredential extends Model
protected $visible = ['id', 'origin', 'alias', 'aaguid', 'attestation_format', 'disabled_at'];

/**
* @phpstan-ignore-next-line
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo|\Laragear\WebAuthn\Contracts\WebAuthnAuthenticatable
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Laragear\WebAuthn\Contracts\WebAuthnAuthenticatable, $this>
*/
public function authenticatable(): MorphTo
public function authenticatable(): MorphTo // @phpstan-ignore-line
{
return $this->morphTo('authenticatable');
return $this->morphTo('authenticatable'); // @phpstan-ignore-line
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/WebAuthn.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@
class WebAuthn extends Http\Routes
{
//

public function something()
{
$some = ['foo', 'bar'];

foreach ($some as $key => $value) {
// code...
}
}
}
4 changes: 2 additions & 2 deletions src/WebAuthnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function boot(): void
*/
protected function publishesPackageMigrations(array|string $paths, string $groups = 'migrations'): void
{
if (method_exists(static::class, 'publishesMigrations')) {
if (method_exists(static::class, 'publishesMigrations')) { // @phpstan-ignore-line
foreach ((array) $paths as $path) {
$this->publishesMigrations([$path => $this->app->databasePath('migrations/')], 'migrations');
}
Expand All @@ -88,7 +88,7 @@ protected function publishesPackageMigrations(array|string $paths, string $group
$files[$file->getRealPath()] = $this->app->databasePath("migrations/{$prefix}_$filename");
}

method_exists($this, 'publishesMigrations')
method_exists($this, 'publishesMigrations') // @phpstan-ignore-line
? $this->publishesMigrations($files, $groups)
: $this->publishes($files, $groups);
}
Expand Down

0 comments on commit d0f127f

Please sign in to comment.