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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/yaml": "^6.4|^7.4|^8.0",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan": "^2.1",
"symplify/easy-coding-standard": "^13.0"
},
"autoload": {
Expand Down
18 changes: 16 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
parameters:
ignoreErrors:
-
message: "#^Property Yokai\\\\SecurityTokenBundle\\\\Entity\\\\Token\\:\\:\\$id is never written, only read\\.$#"
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\\\\TokenUsage\\:\\:\\$id is never written, only read\\.$#"
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
count: 1
path: src/Entity/TokenUsage.php

3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ includes:
- phpstan-baseline.neon
parameters:
level: max
ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.iterableValue
paths:
- src/
5 changes: 3 additions & 2 deletions src/Archive/DeleteArchivist.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use Doctrine\ORM\EntityRepository;
use Yokai\SecurityTokenBundle\Entity\Token;

/**
* This archivist is removing all outdated tokens based on the `keepUntil` property.
Expand All @@ -15,12 +16,12 @@
final class DeleteArchivist implements ArchivistInterface
{
/**
* @var EntityRepository
* @var EntityRepository<Token>
*/
private $tokenRepository;

/**
* @param EntityRepository $tokenRepository The token entity repository
* @param EntityRepository<Token> $tokenRepository The token entity repository
*/
public function __construct(EntityRepository $tokenRepository)
{
Expand Down
34 changes: 31 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@

namespace Yokai\SecurityTokenBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*
* @phpstan-type Config array{
* tokens: array<
* array{
* generator: string,
* duration: string,
* usages: int,
* keep: string,
* unique: bool,
* },
* >,
* services: array{
* information_guesser: string,
* token_factory: string,
* token_repository: string,
* token_manager: string,
* archivist: string,
* },
* }
*/
final class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder<'array'>
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$builder = new TreeBuilder('yokai_security_token');
Expand All @@ -29,7 +51,10 @@ public function getConfigTreeBuilder(): TreeBuilder
return $builder;
}

private function getTokensNode(): NodeDefinition
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function getTokensNode(): ArrayNodeDefinition
{
$builder = new TreeBuilder('tokens');
$node = $builder->getRootNode();
Expand Down Expand Up @@ -60,7 +85,10 @@ private function getTokensNode(): NodeDefinition
return $node;
}

private function getServicesNode(): NodeDefinition
/**
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
*/
private function getServicesNode(): ArrayNodeDefinition
{
$builder = new TreeBuilder('services');
$node = $builder->getRootNode();
Expand Down
11 changes: 9 additions & 2 deletions src/DependencyInjection/YokaiSecurityTokenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

/**
* @author Yann Eugoné <eugone.yann@gmail.com>
*
* @phpstan-import-type Config from Configuration
*/
final class YokaiSecurityTokenExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
/** @var Config $config */
$config = $this->processConfiguration(new Configuration(), $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
Expand All @@ -33,6 +36,9 @@ public function load(array $configs, ContainerBuilder $container): void
$this->registerAutoconfigureAliases($container);
}

/**
* @param Config $config
*/
private function registerTokens(array $config, ContainerBuilder $container): void
{
foreach ($config['tokens'] as $name => $token) {
Expand All @@ -48,10 +54,11 @@ private function registerTokens(array $config, ContainerBuilder $container): voi
}
}

/**
* @param Config $config
*/
private function registerAliases(array $config, ContainerBuilder $container): void
{
$isTest = $container->getParameter('kernel.environment') === 'test';

foreach ($config['services'] as $name => $service) {
$alias = $container->setAlias(\sprintf('yokai_security_token.%s', $name), $service);
$alias->setPublic(true);
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ public function getCreatedAt(): DateTime
return $this->createdAt;
}

/**
* @return array<string, mixed>
*/
public function getCreatedInformation(): array
{
return $this->createdInformation;
Expand Down Expand Up @@ -198,6 +201,8 @@ public function getLastUsage(): TokenUsage|null
}

/**
* @param array<string, mixed> $information
*
* @throws LogicException
*/
public function consume(array $information, DateTime|null $date = null): void
Expand Down
10 changes: 6 additions & 4 deletions src/Event/ConsumeTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ final class ConsumeTokenEvent extends Event
private $at;

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

/**
* @param Token $token The consumed token
* @param DateTime|null $at Date/time at which the token has been consumed
* @param array $information Some context information
* @param Token $token The consumed token
* @param DateTime|null $at Date/time at which the token has been consumed
* @param array<string, mixed> $information Some context information
*/
public function __construct(Token $token, DateTime|null $at, array $information)
{
Expand All @@ -60,6 +60,8 @@ public function getAt(): DateTime|null

/**
* Some context information
*
* @return array<string, mixed>
*/
public function getInformation(): array
{
Expand Down
14 changes: 8 additions & 6 deletions src/Event/CreateTokenEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ final class CreateTokenEvent extends Event
private $user;

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

/**
* @param string $purpose The token purpose
* @param mixed $user The associated user
* @param array $payload The token payload
* @param string $purpose The token purpose
* @param mixed $user The associated user
* @param array<string, mixed> $payload The token payload
*/
public function __construct(string $purpose, $user, array $payload)
{
Expand Down Expand Up @@ -62,6 +62,8 @@ public function getUser()

/**
* The token payload
*
* @return array<string, mixed>
*/
public function getPayload(): array
{
Expand All @@ -71,7 +73,7 @@ public function getPayload(): array
/**
* Replace token payload
*
* @param array $payload The new payload value
* @param array<string, mixed> $payload The new payload value
*/
public function setPayload(array $payload): void
{
Expand All @@ -81,7 +83,7 @@ public function setPayload(array $payload): void
/**
* Add payload information to token
*
* @param array $payload Some payload to add
* @param array<string, mixed> $payload Some payload to add
*/
public function addPayload(array $payload): void
{
Expand Down
6 changes: 5 additions & 1 deletion src/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
}

/**
* @param mixed $user
* @param mixed $user
* @param array<string, mixed> $payload
*/
public function createToken(string $purpose, $user, array $payload): CreateTokenEvent
{
Expand All @@ -53,6 +54,9 @@ public function tokenCreated(Token $token): TokenCreatedEvent
return $event;
}

/**
* @param array<string, mixed> $information
*/
public function consumeToken(Token $token, DateTime|null $at = null, array $information = []): ConsumeTokenEvent
{
$this->eventDispatcher->dispatch(
Expand Down
6 changes: 3 additions & 3 deletions src/Factory/TokenFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ interface TokenFactoryInterface
/**
* Create a new token.
*
* @param mixed $user The to associated to the token
* @param string $purpose The token purpose
* @param array $payload The token payload
* @param mixed $user The to associated to the token
* @param string $purpose The token purpose
* @param array<string, mixed> $payload The token payload
*
* @return Token The created token
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Manager/TokenManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function get(string $purpose, string $value): Token;
/**
* Create a token.
*
* @param string $purpose The token purpose
* @param mixed $user The user to associate to the token
* @param array $payload Some additional payload for the token
* @param string $purpose The token purpose
* @param mixed $user The user to associate to the token
* @param array<string, mixed> $payload Some additional payload for the token
*
* @return Token The created token
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Repository/DoctrineORMTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ final class DoctrineORMTokenRepository implements TokenRepositoryInterface
private $manager;

/**
* @var EntityRepository
* @var EntityRepository<Token>
*/
private $repository;

/**
* @param EntityManager $manager The token entity manager
* @param EntityRepository $repository The token entity repository
* @param EntityManager $manager The token entity manager
* @param EntityRepository<Token> $repository The token entity repository
*/
public function __construct(EntityManager $manager, EntityRepository $repository)
{
Expand Down
Loading