yokai-php /
security-token-bundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Yokai\SecurityTokenBundle\Archive; |
||
| 4 | |||
| 5 | use DateTime; |
||
| 6 | use Doctrine\ORM\EntityRepository; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * This archivist is removing all outdated tokens based on the `keepUntil` property. |
||
| 10 | * |
||
| 11 | * @author Yann Eugoné <[email protected]> |
||
| 12 | */ |
||
| 13 | class DeleteArchivist implements ArchivistInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var EntityRepository |
||
| 17 | */ |
||
| 18 | private $tokenRepository; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param EntityRepository $tokenRepository The token entity repository |
||
| 22 | */ |
||
| 23 | public function __construct(EntityRepository $tokenRepository) |
||
| 24 | { |
||
| 25 | $this->tokenRepository = $tokenRepository; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @inheritDoc |
||
| 30 | */ |
||
| 31 | public function archive(string $purpose = null): int |
||
| 32 | { |
||
| 33 | $builder = $this->tokenRepository->createQueryBuilder('token') |
||
| 34 | ->delete($this->tokenRepository->getClassName(), 'token'); |
||
| 35 | |||
| 36 | $builder |
||
| 37 | ->where($builder->expr()->lt('token.keepUntil', ':now')) |
||
| 38 | ->setParameter('now', new DateTime()) |
||
| 39 | ; |
||
| 40 | |||
| 41 | if ($purpose) { |
||
|
0 ignored issues
–
show
|
|||
| 42 | $builder |
||
| 43 | ->andWhere($builder->expr()->eq('token.purpose', ':purpose')) |
||
| 44 | ->setParameter('purpose', $purpose) |
||
| 45 | ; |
||
| 46 | } |
||
| 47 | |||
| 48 | return intval($builder->getQuery()->execute()); |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: