diff --git a/src/Command/PurgeEntryDeletionsCommand.php b/src/Command/PurgeEntryDeletionsCommand.php index 4d7566eb1..4c76d8d3a 100644 --- a/src/Command/PurgeEntryDeletionsCommand.php +++ b/src/Command/PurgeEntryDeletionsCommand.php @@ -2,7 +2,6 @@ namespace Wallabag\Command; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -17,7 +16,6 @@ class PurgeEntryDeletionsCommand extends Command protected static $defaultDescription = 'Purge old entry deletion records'; public function __construct( - private readonly EntityManagerInterface $entityManager, private readonly EntryDeletionRepository $entryDeletionRepository, private readonly EntryDeletionExpirationConfig $expirationConfig, ) { @@ -46,24 +44,22 @@ class PurgeEntryDeletionsCommand extends Command if ($dryRun) { $io->text('Dry run mode enabled (no records will be deleted)'); + if (0 === $count) { + $io->success('No entry deletion records found.'); + } else { + $io->success(\sprintf('Would have deleted %d records.', $count)); + } return 0; } - if (0 === $count) { $io->success('No entry deletion records found.'); return 0; } - if ($dryRun) { - $io->success(sprintf('Would have deleted %d records.', $count)); - - return 0; - } - - $confirmMessage = sprintf( + $confirmMessage = \sprintf( 'Are you sure you want to delete records older than %s? (count: %d)', $cutoff->format('Y-m-d'), $count, @@ -74,7 +70,7 @@ class PurgeEntryDeletionsCommand extends Command $this->entryDeletionRepository->deleteAllBefore($cutoff); - $io->success(sprintf('Successfully deleted %d records.', $count)); + $io->success(\sprintf('Successfully deleted %d records.', $count)); return 0; } diff --git a/src/Controller/Api/EntryDeletionRestController.php b/src/Controller/Api/EntryDeletionRestController.php index 7ec58197c..29d8edacd 100644 --- a/src/Controller/Api/EntryDeletionRestController.php +++ b/src/Controller/Api/EntryDeletionRestController.php @@ -7,12 +7,11 @@ use Hateoas\Representation\Factory\PagerfantaFactory; use OpenApi\Attributes as OA; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\GoneHttpException; use Symfony\Component\Routing\Annotation\Route; use Wallabag\Entity\EntryDeletion; use Wallabag\Helper\EntryDeletionExpirationConfig; -use Wallabag\Repository\EntryDeletionRepository; use Wallabag\OpenApi\Attribute as WOA; +use Wallabag\Repository\EntryDeletionRepository; class EntryDeletionRestController extends WallabagRestController { @@ -33,7 +32,7 @@ class EntryDeletionRestController extends WallabagRestController ), new WOA\OrderParameter(), new WOA\PagerFanta\PageParameter(), - new WOA\PagerFanta\PerPageParameter(default: 100) + new WOA\PagerFanta\PerPageParameter(default: 100), ], responses: [ new OA\Response( @@ -57,22 +56,22 @@ class EntryDeletionRestController extends WallabagRestController schema: new OA\Schema(type: 'integer') ), ] - ) + ), ] )] #[IsGranted('LIST_ENTRIES')] public function getEntryDeletionsAction( Request $request, EntryDeletionRepository $entryDeletionRepository, - EntryDeletionExpirationConfig $expirationConfig + EntryDeletionExpirationConfig $expirationConfig, ) { $this->validateAuthentication(); $userId = $this->getUser()->getId(); - $page = $request->query->get('page', 1); - $perPage = $request->query->get('perPage', 100); - $order = $request->query->get('order', 'desc'); - $since = (int)$request->query->get('since', 0); + $page = $request->query->getInt('page', 1); + $perPage = $request->query->getInt('perPage', 100); + $order = strtolower($request->query->get('order', 'desc')); + $since = $request->query->getInt('since', 0); if (!\in_array($order, ['asc', 'desc'], true)) { $order = 'desc'; @@ -85,7 +84,7 @@ class EntryDeletionRestController extends WallabagRestController return $this->json( [ 'message' => "The requested since date ({$since}) is before the data retention cutoff date ({$cutoff}).\n" - . "You can get the cutoff date programmatically from the X-Wallabag-Entry-Deletion-Cutoff header.", + . 'You can get the cutoff date programmatically from the X-Wallabag-Entry-Deletion-Cutoff header.', ], 410, headers: [ diff --git a/src/Helper/EntryDeletionExpirationConfig.php b/src/Helper/EntryDeletionExpirationConfig.php index e6d764b24..55d981693 100644 --- a/src/Helper/EntryDeletionExpirationConfig.php +++ b/src/Helper/EntryDeletionExpirationConfig.php @@ -28,6 +28,7 @@ class EntryDeletionExpirationConfig public function setExpirationDays(int $days): self { $this->expirationDays = $days; + return $this; } } diff --git a/src/OpenApi/Attribute/OrderParameter.php b/src/OpenApi/Attribute/OrderParameter.php index 1b6e67ecf..2bd856060 100644 --- a/src/OpenApi/Attribute/OrderParameter.php +++ b/src/OpenApi/Attribute/OrderParameter.php @@ -3,9 +3,8 @@ namespace Wallabag\OpenApi\Attribute; use OpenApi\Attributes as OA; -use Attribute; -#[Attribute(Attribute::TARGET_METHOD)] +#[\Attribute(\Attribute::TARGET_METHOD)] class OrderParameter extends OA\Parameter { public function __construct( diff --git a/src/OpenApi/Attribute/PagerFanta/JsonContent.php b/src/OpenApi/Attribute/PagerFanta/JsonContent.php index eb0850056..2e27b2daf 100644 --- a/src/OpenApi/Attribute/PagerFanta/JsonContent.php +++ b/src/OpenApi/Attribute/PagerFanta/JsonContent.php @@ -4,9 +4,8 @@ namespace Wallabag\OpenApi\Attribute\PagerFanta; use Nelmio\ApiDocBundle\Attribute\Model; use OpenApi\Attributes as OA; -use Attribute; -#[Attribute(Attribute::TARGET_CLASS)] +#[\Attribute(\Attribute::TARGET_CLASS)] class JsonContent extends OA\JsonContent { public function __construct(string|array|null $modelClass = null) @@ -21,7 +20,7 @@ class JsonContent extends OA\JsonContent property: 'items', type: 'array', items: new OA\Items(ref: new Model(type: $modelClass)) - ) + ), ] ), new OA\Property(property: 'page', type: 'integer'), @@ -51,9 +50,9 @@ class JsonContent extends OA\JsonContent property: 'next', type: 'object', properties: [new OA\Property(property: 'href', type: 'string')] - ) + ), ] - ) + ), ] ); } diff --git a/src/OpenApi/Attribute/PagerFanta/PageParameter.php b/src/OpenApi/Attribute/PagerFanta/PageParameter.php index 49460cb5f..110699383 100644 --- a/src/OpenApi/Attribute/PagerFanta/PageParameter.php +++ b/src/OpenApi/Attribute/PagerFanta/PageParameter.php @@ -3,9 +3,8 @@ namespace Wallabag\OpenApi\Attribute\PagerFanta; use OpenApi\Attributes as OA; -use Attribute; -#[Attribute(Attribute::TARGET_METHOD)] +#[\Attribute(\Attribute::TARGET_METHOD)] class PageParameter extends OA\Parameter { public function __construct( diff --git a/src/OpenApi/Attribute/PagerFanta/PerPageParameter.php b/src/OpenApi/Attribute/PagerFanta/PerPageParameter.php index 098410151..77d72ef19 100644 --- a/src/OpenApi/Attribute/PagerFanta/PerPageParameter.php +++ b/src/OpenApi/Attribute/PagerFanta/PerPageParameter.php @@ -3,9 +3,8 @@ namespace Wallabag\OpenApi\Attribute\PagerFanta; use OpenApi\Attributes as OA; -use Attribute; -#[Attribute(Attribute::TARGET_METHOD)] +#[\Attribute(\Attribute::TARGET_METHOD)] class PerPageParameter extends OA\Parameter { public function __construct( diff --git a/src/Repository/EntryDeletionRepository.php b/src/Repository/EntryDeletionRepository.php index 22d70c3b5..2107d07dd 100644 --- a/src/Repository/EntryDeletionRepository.php +++ b/src/Repository/EntryDeletionRepository.php @@ -17,14 +17,8 @@ class EntryDeletionRepository extends ServiceEntityRepository /** * Find deletions for a specific user since a given date. The result is paginated. - * - * @param int $userId - * @param int $since - * @param int $page - * @param int $perPage - * @param string $order */ - public function findEntryDeletions($userId, $since = 0, $order = 'asc'): Pagerfanta + public function findEntryDeletions(int $userId, int $since = 0, string $order = 'asc'): Pagerfanta { $qb = $this->createQueryBuilder('de') ->where('de.user = :userId')->setParameter('userId', $userId) diff --git a/tests/Command/PurgeEntryDeletionsCommandTest.php b/tests/Command/PurgeEntryDeletionsCommandTest.php index 3fa8872f5..53a472e72 100644 --- a/tests/Command/PurgeEntryDeletionsCommandTest.php +++ b/tests/Command/PurgeEntryDeletionsCommandTest.php @@ -12,7 +12,7 @@ use Wallabag\Repository\EntryDeletionRepository; /** * Test the purge entry deletions command. - * + * * The fixtures set up the following entry deletions: * - Admin user: 1 deletion from 4 days ago (entry_id: 1004) * - Admin user: 1 deletion from 1 day ago (entry_id: 1001) diff --git a/tests/Controller/Api/EntryDeletionRestControllerTest.php b/tests/Controller/Api/EntryDeletionRestControllerTest.php index f2a5359b5..104cdf0e8 100644 --- a/tests/Controller/Api/EntryDeletionRestControllerTest.php +++ b/tests/Controller/Api/EntryDeletionRestControllerTest.php @@ -4,12 +4,12 @@ namespace Tests\Wallabag\Controller\Api; /** * Test the entry deletion REST API endpoints. - * + * * The fixtures set up the following entry deletions: * - Admin user: 1 deletion from 4 days ago (entry_id: 1004) * - Admin user: 1 deletion from 1 day ago (entry_id: 1001) * - Bob user: 1 deletion from 3 days ago (entry_id: 1003) - * + * * The logged in user is admin. */ class EntryDeletionRestControllerTest extends WallabagApiTestCase @@ -21,7 +21,7 @@ class EntryDeletionRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); // check that only the items for the current user are returned - $this->assertEquals(2, \count($content['_embedded']['items'])); + $this->assertCount(2, $content['_embedded']['items']); // validate the deletion schema on the first item $deletionData = $content['_embedded']['items'][0];