mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 16:53:11 +08:00
Migrated all constructor props to property promotion when possible
This commit is contained in:
@@ -15,11 +15,8 @@ use function sprintf;
|
||||
|
||||
class ApiKeyService implements ApiKeyServiceInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(private EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function create(
|
||||
@@ -40,20 +37,14 @@ class ApiKeyService implements ApiKeyServiceInterface
|
||||
|
||||
private function buildApiKeyWithParams(?Chronos $expirationDate, ?string $name): ApiKey
|
||||
{
|
||||
// TODO Use match expression when migrating to PHP8
|
||||
if ($expirationDate === null && $name === null) {
|
||||
return ApiKey::create();
|
||||
}
|
||||
|
||||
if ($expirationDate !== null && $name !== null) {
|
||||
return ApiKey::fromMeta(ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate));
|
||||
}
|
||||
|
||||
if ($name === null) {
|
||||
return ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate));
|
||||
}
|
||||
|
||||
return ApiKey::fromMeta(ApiKeyMeta::withName($name));
|
||||
return match (true) {
|
||||
$expirationDate === null && $name === null => ApiKey::create(),
|
||||
$expirationDate !== null && $name !== null => ApiKey::fromMeta(
|
||||
ApiKeyMeta::withNameAndExpirationDate($name, $expirationDate),
|
||||
),
|
||||
$name === null => ApiKey::fromMeta(ApiKeyMeta::withExpirationDate($expirationDate)),
|
||||
default => ApiKey::fromMeta(ApiKeyMeta::withName($name)),
|
||||
};
|
||||
}
|
||||
|
||||
public function check(string $key): ApiKeyCheckResult
|
||||
|
||||
Reference in New Issue
Block a user