Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/5-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ class LogSecurityTokenErrors implements EventSubscriberInterface
{
$this->logger->warning(
'Security token was not found',
['purpose' => $event->getPurpose(), 'value' => $event->getValue()]
['purpose' => $event->purpose, 'value' => $event->value]
);
}

public function onTokenExpired(SecurityTokenEvents\TokenExpiredEvent $event): void
{
$this->logger->warning(
'Security token was expired',
['purpose' => $event->getPurpose(), 'value' => $event->getValue()]
['purpose' => $event->purpose, 'value' => $event->value]
);
}

public function onTokenConsumed(SecurityTokenEvents\TokenAlreadyConsumedEvent $event): void
{
$this->logger->warning(
'Security token was already consumed',
['purpose' => $event->getPurpose(), 'value' => $event->getValue()]
['purpose' => $event->purpose, 'value' => $event->value]
);
}
}
Expand Down
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
parameters:
ignoreErrors:
-
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\Token\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: src/Entity/Token.php

-
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\Token\:\:\$id is never written, only read\.$#'
identifier: property.onlyRead
count: 1
path: src/Entity/Token.php

-
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\TokenUsage\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: src/Entity/TokenUsage.php

-
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\TokenUsage\:\:\$id is never written, only read\.$#'
identifier: property.onlyRead
Expand Down
2 changes: 1 addition & 1 deletion src/Archive/ArchivistInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ArchivistInterface
*
* @param string|null $purpose The token purpose
*
* @return integer
* @return int Count archived tokens
*/
public function archive(string|null $purpose = null): int;
}
17 changes: 6 additions & 11 deletions src/Archive/DeleteArchivist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
*/
final class DeleteArchivist implements ArchivistInterface
{
/**
* @var EntityRepository<Token>
*/
private $tokenRepository;

/**
* @param EntityRepository<Token> $tokenRepository The token entity repository
*/
public function __construct(EntityRepository $tokenRepository)
{
$this->tokenRepository = $tokenRepository;
public function __construct(
/**
* @var EntityRepository<Token> The token entity repository
*/
private readonly EntityRepository $tokenRepository,
) {
}

public function archive(string|null $purpose = null): int
Expand Down
13 changes: 4 additions & 9 deletions src/Command/ArchiveTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,9 @@
*/
final class ArchiveTokenCommand extends Command
{
/**
* @var ArchivistInterface
*/
private $archivist;

public function __construct(ArchivistInterface $archivist)
{
$this->archivist = $archivist;
public function __construct(
private readonly ArchivistInterface $archivist,
) {
parent::__construct();
}

Expand All @@ -45,6 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
\sprintf('<info>Successfully archived <comment>%d</comment> security token(s).</info>', $count),
);

return 0;
return self::SUCCESS;
}
}
78 changes: 6 additions & 72 deletions src/Configuration/TokenConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,79 +11,13 @@
*/
final class TokenConfiguration
{
/**
* @var string
*/
private $purpose;

/**
* @var TokenGeneratorInterface
*/
private $generator;

/**
* @var string
*/
private $duration;

/**
* @var int
*/
private $usages;

/**
* @var string
*/
private $keep;

/**
* @var bool
*/
private $unique;

public function __construct(
string $purpose,
TokenGeneratorInterface $generator,
string $duration,
int $usages,
string $keep,
bool $unique,
public readonly string $purpose,
public readonly TokenGeneratorInterface $generator,
public readonly string $duration,
public readonly int $usages,
public readonly string $keep,
public readonly bool $unique,
) {
$this->purpose = $purpose;
$this->generator = $generator;
$this->duration = $duration;
$this->usages = $usages;
$this->keep = $keep;
$this->unique = $unique;
}

public function getPurpose(): string
{
return $this->purpose;
}

public function getGenerator(): TokenGeneratorInterface
{
return $this->generator;
}

public function getDuration(): string
{
return $this->duration;
}

public function getUsages(): int
{
return $this->usages;
}

public function getKeep(): string
{
return $this->keep;
}

public function isUnique(): bool
{
return $this->unique;
}
}
18 changes: 8 additions & 10 deletions src/Configuration/TokenConfigurationRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
final class TokenConfigurationRegistry
{
/**
* @var array<TokenConfiguration>
* @var array<string, TokenConfiguration>
*/
private $configurations;
private readonly array $configurations;

/**
* @param array<TokenConfiguration> $configurations
* @param list<TokenConfiguration> $configurations
*/
public function __construct(array $configurations)
{
$this->configurations = [];
$indexedConfigurations = [];
foreach ($configurations as $configuration) {
$this->configurations[$configuration->getPurpose()] = $configuration;
$indexedConfigurations[$configuration->purpose] = $configuration;
}
$this->configurations = $indexedConfigurations;
}

/**
Expand All @@ -36,12 +37,9 @@ public function __construct(array $configurations)
*/
public function get(string $purpose): TokenConfiguration
{
if (!isset($this->configurations[$purpose])) {
throw new BadMethodCallException(
return $this->configurations[$purpose]
?? throw new BadMethodCallException(
\sprintf('There is no configured security token on "%s" purpose.', $purpose),
);
}

return $this->configurations[$purpose];
}
}
50 changes: 13 additions & 37 deletions src/Entity/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,65 +14,41 @@
*/
class Token
{
/**
* @var int|null
*/
private $id;
private int|null $id;

/**
* @var class-string
*/
private $userClass;
private string $userClass;

/**
* @var string
*/
private $userId;
private string $userId;

/**
* @var string
*/
private $value;
private string $value;

/**
* @var string
*/
private $purpose;
private string $purpose;

/**
* @var array<string, mixed>
*/
private $payload = [];
private array $payload;

/**
* @var DateTime
*/
private $createdAt;
private DateTime $createdAt;

/**
* @var array<string, mixed>
*/
private $createdInformation = [];
private array $createdInformation;

/**
* @var integer
*/
private $allowedUsages;
private int $allowedUsages;

/**
* @var DateTime
*/
private $expiresAt;
private DateTime $expiresAt;

/**
* @var DateTime
*/
private $keepUntil;
private DateTime $keepUntil;

/**
* @var Collection<int, TokenUsage>
*/
private $usages;
private Collection $usages;

/**
* @param class-string $userClass
Expand Down Expand Up @@ -188,7 +164,7 @@ public function getCountUsages(): int
}

/**
* @return array<TokenUsage>
* @return array<int, TokenUsage>
*/
public function getUsages(): array
{
Expand Down
17 changes: 4 additions & 13 deletions src/Entity/TokenUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,16 @@

class TokenUsage
{
/**
* @var int|null
*/
private $id;
private int|null $id;

/**
* @var Token
*/
private $token;
private Token $token;

/**
* @var DateTime
*/
private $createdAt;
private DateTime $createdAt;

/**
* @var array<string, mixed>
*/
private $information = [];
private array $information = [];

/**
* @param array<string, mixed> $information
Expand Down
Loading
Loading