Skip to content

Commit

Permalink
Merge pull request #139 from samsonasik/update-to-latest-php81-syntax
Browse files Browse the repository at this point in the history
Update to latest PHP 8.1 syntax
  • Loading branch information
gsteel authored Nov 3, 2024
2 parents 7aed2ae + 0a3b998 commit 64990c7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 35 deletions.
18 changes: 5 additions & 13 deletions src/DefaultUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@
*/
final class DefaultUser implements UserInterface
{
private string $identity;

/** @psalm-var array<int|string, string> */
private $roles;

/** @psalm-var array<string, mixed> */
private $details;

/**
* @psalm-param array<int|string, string> $roles
* @psalm-param array<string, mixed> $details
*/
public function __construct(string $identity, array $roles = [], array $details = [])
{
$this->identity = $identity;
$this->roles = $roles;
$this->details = $details;
public function __construct(
private readonly string $identity,
private readonly array $roles = [],
private array $details = []
) {
}

public function getIdentity(): string
Expand Down
6 changes: 3 additions & 3 deletions src/UserRepository/Htpasswd.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use function fopen;
use function password_verify;
use function sprintf;
use function strpos;
use function str_starts_with;
use function trim;

/**
Expand All @@ -27,7 +27,7 @@
*/
class Htpasswd implements UserRepositoryInterface
{
private string $filename;
private readonly string $filename;

/**
* @var callable
Expand Down Expand Up @@ -98,7 +98,7 @@ public function authenticate(string $credential, ?string $password = null): ?Use
*/
protected function checkBcryptHash(string $hash): void
{
if (0 !== strpos($hash, '$2y$')) {
if (! str_starts_with($hash, '$2y$')) {
throw new Exception\RuntimeException(
'The htpasswd file uses not secure hash algorithm. Please use bcrypt.'
);
Expand Down
18 changes: 5 additions & 13 deletions src/UserRepository/PdoDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use function password_verify;
use function sprintf;
use function strpos;
use function str_contains;

/**
* Adapter for PDO database
Expand All @@ -22,11 +22,6 @@
*/
class PdoDatabase implements UserRepositoryInterface
{
private PDO $pdo;

/** @psalm-var array<string, mixed> */
private $config;

/**
* @var callable
* @psalm-var callable(string, array<int|string, string>, array<string, mixed>): UserInterface
Expand All @@ -38,13 +33,10 @@ class PdoDatabase implements UserRepositoryInterface
* @psalm-param callable(string, array<int|string, string>, array<string, mixed>): UserInterface $userFactory
*/
public function __construct(
PDO $pdo,
array $config,
private readonly PDO $pdo,
private array $config,
callable $userFactory
) {
$this->pdo = $pdo;
$this->config = $config;

// Provide type safety for the composed user factory.
$this->userFactory = static function (
string $identity,
Expand Down Expand Up @@ -114,7 +106,7 @@ protected function getUserRoles(string $identity): array

Assert::string($this->config['sql_get_roles']);

if (false === strpos($this->config['sql_get_roles'], ':identity')) {
if (! str_contains($this->config['sql_get_roles'], ':identity')) {
throw new Exception\InvalidConfigException(
'The sql_get_roles configuration setting must include an :identity parameter'
);
Expand Down Expand Up @@ -160,7 +152,7 @@ protected function getUserDetails(string $identity): array

Assert::string($this->config['sql_get_details']);

if (false === strpos($this->config['sql_get_details'], ':identity')) {
if (! str_contains($this->config['sql_get_details'], ':identity')) {
throw new Exception\InvalidConfigException(
'The sql_get_details configuration setting must include a :identity parameter'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
*/
final class ConfigImplementingArrayAccess implements ArrayAccess
{
/** @var array<array-key,mixed> */
private array $data;

/**
* @param array<string,mixed> $data
* @param array<array-key,mixed> $data
*/
public function __construct(array $data)
public function __construct(private array $data)
{
$this->data = $data;
}

/**
Expand Down

0 comments on commit 64990c7

Please sign in to comment.