Skip to content

Commit

Permalink
Set properties as readonly
Browse files Browse the repository at this point in the history
Uses Closure::fromCallable() so Closure type can be used
  • Loading branch information
little-apps committed Jun 2, 2024
1 parent b4fccf5 commit f40a1db
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/Core/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Handler
*
* @var Application
*/
protected $app;
protected readonly Application $app;

/**
* The JWK to use for building and validating JWTs
*
* @var JsonWebKey
*/
protected $jwk;
protected readonly JsonWebKey $jwk;

/**
* Intializes LittleJWT instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/DefaultCallbackBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DefaultCallbackBuilder
*
* @var Application
*/
protected $app;
protected readonly Application $app;

public function __construct(Application $app)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/OpenSSLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OpenSSLBuilder
*
* @var array
*/
protected $config;
protected readonly array $config;

/**
* Initializes OpenSSLBuilder instance.
Expand Down
4 changes: 2 additions & 2 deletions src/Guards/Adapters/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ abstract class AbstractAdapter implements GuardAdapter
*
* @var Container
*/
protected $container;
protected readonly Container $container;

/**
* The options to use for the adapter.
*
* @var array
*/
protected $config;
protected readonly array $config;

public function __construct(Container $container, array $config)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Guards/Adapters/FingerprintAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class FingerprintAdapter extends AbstractAdapter
*
* @var AbstractAdapter
*/
protected $baseAdapter;
protected readonly AbstractAdapter $baseAdapter;

/**
* Intializes fingerprint adapter.
Expand Down
4 changes: 2 additions & 2 deletions src/Guards/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Guard implements GuardContract
*
* @var Container
*/
protected $container;
protected readonly Container $container;

/**
* The guard adapter to use.
Expand All @@ -44,7 +44,7 @@ class Guard implements GuardContract
*
* @var array
*/
protected $config;
protected readonly array $config;

public function __construct(Container $container, GuardAdapter $adapter, UserProvider $provider, Request $request, array $config)
{
Expand Down
4 changes: 2 additions & 2 deletions src/JWT/ClaimManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class ClaimManager implements Arrayable, ArrayAccess, Countable, Jsonable
*
* @var string One of ClaimManager::PART_* constants
*/
protected $part;
protected readonly string $part;

/**
* Claims
*
* @var \Illuminate\Support\Collection<string, ClaimBuildOptions>
*/
protected $claims;
protected readonly Collection $claims;

public function __construct(string $part, $claims)
{
Expand Down
4 changes: 2 additions & 2 deletions src/JWT/JsonWebToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class JsonWebToken
*
* @var ClaimManager
*/
protected $headers;
protected readonly ClaimManager $headers;

/**
* Payload claim manager.
*
* @var ClaimManager
*/
protected $payload;
protected readonly ClaimManager $payload;

/**
* Creates an instance that represents a JWT.
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/MutatedJsonWebToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MutatedJsonWebToken extends JsonWebToken
*
* @var JsonWebToken
*/
protected $original;
protected readonly JsonWebToken $original;

/**
* Creates an instance that represents a JWT.
Expand Down
2 changes: 1 addition & 1 deletion src/JWT/SignedJsonWebToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SignedJsonWebToken extends JsonWebToken
*
* @var string
*/
protected $signature;
protected readonly string $signature;

/**
* Creates an instance that represents a JWT.
Expand Down
5 changes: 3 additions & 2 deletions src/Laravel/Rules/ValidToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LittleApps\LittleJWT\Laravel\Rules;

use Closure;
use Illuminate\Contracts\Validation\ImplicitRule;
use LittleApps\LittleJWT\Facades\LittleJWT;
use LittleApps\LittleJWT\JWT\JsonWebToken;
Expand All @@ -13,7 +14,7 @@ class ValidToken implements ImplicitRule
*
* @var callable(\LittleApps\LittleJWT\Validation\Validator): void
*/
protected $callback;
protected readonly ?Closure $callback;

/**
* Initializes implicit valid token rule.
Expand All @@ -22,7 +23,7 @@ class ValidToken implements ImplicitRule
*/
public function __construct(?callable $callback = null)
{
$this->callback = $callback;
$this->callback = !is_null($callback) ? Closure::fromCallable($callback) : null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Mutate/Mutate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Mutate
*
* @var JWTBuilder
*/
protected $builder;
protected readonly JWTBuilder $builder;

/**
* Mutator Manager
*
* @var MutatorManager
*/
protected $mutatorManager;
protected readonly MutatorManager $mutatorManager;

/**
* Initializes Mutate instance.
Expand Down
7 changes: 4 additions & 3 deletions src/Mutate/MutatedValidatedJsonWebToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LittleApps\LittleJWT\Mutate;

use Closure;
use LittleApps\LittleJWT\JWT\JsonWebToken;
use LittleApps\LittleJWT\Validation\ValidatedJsonWebToken;

Expand All @@ -10,9 +11,9 @@ class MutatedValidatedJsonWebToken extends ValidatedJsonWebToken
/**
* Holds callback to unserialize JWT
*
* @var callable(JsonWebToken): JsonWebToken
* @var Closure(JsonWebToken): JsonWebToken
*/
protected $unserializeCallback;
protected readonly Closure $unserializeCallback;

/**
* Unserialized/mutated JWT
Expand All @@ -36,7 +37,7 @@ public function __construct(ValidatedJsonWebToken $validated, callable $unserial
* there maybe an error unserializing the JWT and we'll
* wait for a call to unserialized() to throw that exception.
*/
$this->unserializeCallback = $unserializeCallback;
$this->unserializeCallback = Closure::fromCallable($unserializeCallback);
$this->unserialized = null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mutate/MutatorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MutatorManager
*
* @var MutatorResolver
*/
protected $resolver;
protected readonly MutatorResolver $resolver;

/**
* Application container
Expand Down
4 changes: 2 additions & 2 deletions src/Mutate/MutatorResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class MutatorResolver
*
* @var Application
*/
protected $app;
protected readonly Application $app;

/**
* Custom mutator mappings
*
* @var array<string, class-string<\LittleApps\LittleJWT\Contracts\Mutator>>
*/
protected $customMutatorsMapping = [
protected array $customMutatorsMapping = [

];

Expand Down
7 changes: 4 additions & 3 deletions src/Mutate/Mutators.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LittleApps\LittleJWT\Mutate;

use BadMethodCallException;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Macroable;

class Mutators
Expand All @@ -16,21 +17,21 @@ class Mutators
*
* @var \Illuminate\Support\Collection
*/
protected $global;
protected readonly Collection $global;

/**
* Mutators that will be applied to header claims.
*
* @var \Illuminate\Support\Collection
*/
protected $headers;
protected readonly Collection $headers;

/**
* Mutators that will be applied to payload claims.
*
* @var \Illuminate\Support\Collection
*/
protected $payload;
protected readonly Collection $payload;

public function __construct(array $global = [], array $headers = [], array $payload = [])
{
Expand Down
9 changes: 5 additions & 4 deletions src/Validation/Valid.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use LittleApps\LittleJWT\Contracts\BuildsValidatorRules;
use LittleApps\LittleJWT\Contracts\Rule;
use LittleApps\LittleJWT\Exceptions\RuleFailedException;
use LittleApps\LittleJWT\JWK\JsonWebKey;
use LittleApps\LittleJWT\JWT\JsonWebToken;

class Valid
Expand All @@ -21,21 +22,21 @@ class Valid
*
* @var Application
*/
protected $app;
protected readonly Application $app;

/**
* JWT to validate
*
* @var JsonWebToken
*/
protected $jwt;
protected readonly JsonWebToken $jwt;

/**
* JSON Web Key to verify signature with
*
* @var JWK
* @var JsonWebKey
*/
protected $jwk;
protected readonly JsonWebKey $jwk;

/**
* Any errors that occurred.
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validatables/DefaultValidatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DefaultValidatable
*
* @var array
*/
protected $config;
protected readonly array $config;

/**
* Intializes default validatable.
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validatables/FingerprintValidatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FingerprintValidatable
*
* @var string
*/
protected $fingerprintHash;
protected readonly string $fingerprintHash;

/**
* Initalizes fingerprint validatable.
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validatables/GuardValidatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GuardValidatable
*
* @var array
*/
protected $config;
protected readonly array $config;

/**
* Initializes guard validatable.
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validatables/StackValidatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StackValidatable
*
* @var list<Validatable|callable(Validator): void>
*/
protected $stack;
protected readonly array $stack;

/**
* Initializes stack validatable.
Expand Down
4 changes: 2 additions & 2 deletions src/Validation/ValidatedJsonWebToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class ValidatedJsonWebToken
*
* @var JsonWebToken
*/
protected $jwt;
protected readonly JsonWebToken $jwt;

/**
* The result of the validation.
*
* @var bool
*/
protected $result;
protected readonly bool $result;

/**
* Initializes instance.
Expand Down
7 changes: 4 additions & 3 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LittleApps\LittleJWT\Validation;

use Closure;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Macroable;
use LittleApps\LittleJWT\Blacklist\BlacklistManager;
use LittleApps\LittleJWT\Contracts\BuildsValidatorRules;
Expand All @@ -20,21 +21,21 @@ class Validator implements BuildsValidatorRules
*
* @var \Illuminate\Support\Collection
*/
protected $rulesBefore;
protected readonly Collection $rulesBefore;

/**
* Rules to run through JWT
*
* @var \Illuminate\Support\Collection
*/
protected $rules;
protected readonly Collection $rules;

/**
* Callbacks to call after rules are checked.
*
* @var \Illuminate\Support\Collection
*/
protected $after;
protected readonly Collection $after;

/**
* If true, the validation ends immediately when a rule fails.
Expand Down

0 comments on commit f40a1db

Please sign in to comment.