1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-31 18:31:02 +00:00

round of make phpstan fix-cs

This commit is contained in:
Martin Chaine 2025-06-04 11:36:44 +02:00
parent 1883ff1380
commit 1fb17a17b6
No known key found for this signature in database
GPG key ID: 2D04DFDC89D53FDE
10 changed files with 29 additions and 43 deletions

View file

@ -2,7 +2,6 @@
namespace Wallabag\Command; namespace Wallabag\Command;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -17,7 +16,6 @@ class PurgeEntryDeletionsCommand extends Command
protected static $defaultDescription = 'Purge old entry deletion records'; protected static $defaultDescription = 'Purge old entry deletion records';
public function __construct( public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly EntryDeletionRepository $entryDeletionRepository, private readonly EntryDeletionRepository $entryDeletionRepository,
private readonly EntryDeletionExpirationConfig $expirationConfig, private readonly EntryDeletionExpirationConfig $expirationConfig,
) { ) {
@ -46,24 +44,22 @@ class PurgeEntryDeletionsCommand extends Command
if ($dryRun) { if ($dryRun) {
$io->text('Dry run mode <info>enabled</info> (no records will be deleted)'); $io->text('Dry run mode <info>enabled</info> (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; return 0;
} }
if (0 === $count) { if (0 === $count) {
$io->success('No entry deletion records found.'); $io->success('No entry deletion records found.');
return 0; return 0;
} }
if ($dryRun) { $confirmMessage = \sprintf(
$io->success(sprintf('Would have deleted %d records.', $count));
return 0;
}
$confirmMessage = sprintf(
'Are you sure you want to delete records older than %s? (count: %d)', 'Are you sure you want to delete records older than %s? (count: %d)',
$cutoff->format('Y-m-d'), $cutoff->format('Y-m-d'),
$count, $count,
@ -74,7 +70,7 @@ class PurgeEntryDeletionsCommand extends Command
$this->entryDeletionRepository->deleteAllBefore($cutoff); $this->entryDeletionRepository->deleteAllBefore($cutoff);
$io->success(sprintf('Successfully deleted %d records.', $count)); $io->success(\sprintf('Successfully deleted %d records.', $count));
return 0; return 0;
} }

View file

@ -7,12 +7,11 @@ use Hateoas\Representation\Factory\PagerfantaFactory;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\GoneHttpException;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Wallabag\Entity\EntryDeletion; use Wallabag\Entity\EntryDeletion;
use Wallabag\Helper\EntryDeletionExpirationConfig; use Wallabag\Helper\EntryDeletionExpirationConfig;
use Wallabag\Repository\EntryDeletionRepository;
use Wallabag\OpenApi\Attribute as WOA; use Wallabag\OpenApi\Attribute as WOA;
use Wallabag\Repository\EntryDeletionRepository;
class EntryDeletionRestController extends WallabagRestController class EntryDeletionRestController extends WallabagRestController
{ {
@ -33,7 +32,7 @@ class EntryDeletionRestController extends WallabagRestController
), ),
new WOA\OrderParameter(), new WOA\OrderParameter(),
new WOA\PagerFanta\PageParameter(), new WOA\PagerFanta\PageParameter(),
new WOA\PagerFanta\PerPageParameter(default: 100) new WOA\PagerFanta\PerPageParameter(default: 100),
], ],
responses: [ responses: [
new OA\Response( new OA\Response(
@ -57,22 +56,22 @@ class EntryDeletionRestController extends WallabagRestController
schema: new OA\Schema(type: 'integer') schema: new OA\Schema(type: 'integer')
), ),
] ]
) ),
] ]
)] )]
#[IsGranted('LIST_ENTRIES')] #[IsGranted('LIST_ENTRIES')]
public function getEntryDeletionsAction( public function getEntryDeletionsAction(
Request $request, Request $request,
EntryDeletionRepository $entryDeletionRepository, EntryDeletionRepository $entryDeletionRepository,
EntryDeletionExpirationConfig $expirationConfig EntryDeletionExpirationConfig $expirationConfig,
) { ) {
$this->validateAuthentication(); $this->validateAuthentication();
$userId = $this->getUser()->getId(); $userId = $this->getUser()->getId();
$page = $request->query->get('page', 1); $page = $request->query->getInt('page', 1);
$perPage = $request->query->get('perPage', 100); $perPage = $request->query->getInt('perPage', 100);
$order = $request->query->get('order', 'desc'); $order = strtolower($request->query->get('order', 'desc'));
$since = (int)$request->query->get('since', 0); $since = $request->query->getInt('since', 0);
if (!\in_array($order, ['asc', 'desc'], true)) { if (!\in_array($order, ['asc', 'desc'], true)) {
$order = 'desc'; $order = 'desc';
@ -85,7 +84,7 @@ class EntryDeletionRestController extends WallabagRestController
return $this->json( return $this->json(
[ [
'message' => "The requested since date ({$since}) is before the data retention cutoff date ({$cutoff}).\n" '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, 410,
headers: [ headers: [

View file

@ -28,6 +28,7 @@ class EntryDeletionExpirationConfig
public function setExpirationDays(int $days): self public function setExpirationDays(int $days): self
{ {
$this->expirationDays = $days; $this->expirationDays = $days;
return $this; return $this;
} }
} }

View file

@ -3,9 +3,8 @@
namespace Wallabag\OpenApi\Attribute; namespace Wallabag\OpenApi\Attribute;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::TARGET_METHOD)]
class OrderParameter extends OA\Parameter class OrderParameter extends OA\Parameter
{ {
public function __construct( public function __construct(

View file

@ -4,9 +4,8 @@ namespace Wallabag\OpenApi\Attribute\PagerFanta;
use Nelmio\ApiDocBundle\Attribute\Model; use Nelmio\ApiDocBundle\Attribute\Model;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Attribute;
#[Attribute(Attribute::TARGET_CLASS)] #[\Attribute(\Attribute::TARGET_CLASS)]
class JsonContent extends OA\JsonContent class JsonContent extends OA\JsonContent
{ {
public function __construct(string|array|null $modelClass = null) public function __construct(string|array|null $modelClass = null)
@ -21,7 +20,7 @@ class JsonContent extends OA\JsonContent
property: 'items', property: 'items',
type: 'array', type: 'array',
items: new OA\Items(ref: new Model(type: $modelClass)) items: new OA\Items(ref: new Model(type: $modelClass))
) ),
] ]
), ),
new OA\Property(property: 'page', type: 'integer'), new OA\Property(property: 'page', type: 'integer'),
@ -51,9 +50,9 @@ class JsonContent extends OA\JsonContent
property: 'next', property: 'next',
type: 'object', type: 'object',
properties: [new OA\Property(property: 'href', type: 'string')] properties: [new OA\Property(property: 'href', type: 'string')]
) ),
] ]
) ),
] ]
); );
} }

View file

@ -3,9 +3,8 @@
namespace Wallabag\OpenApi\Attribute\PagerFanta; namespace Wallabag\OpenApi\Attribute\PagerFanta;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::TARGET_METHOD)]
class PageParameter extends OA\Parameter class PageParameter extends OA\Parameter
{ {
public function __construct( public function __construct(

View file

@ -3,9 +3,8 @@
namespace Wallabag\OpenApi\Attribute\PagerFanta; namespace Wallabag\OpenApi\Attribute\PagerFanta;
use OpenApi\Attributes as OA; use OpenApi\Attributes as OA;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::TARGET_METHOD)]
class PerPageParameter extends OA\Parameter class PerPageParameter extends OA\Parameter
{ {
public function __construct( public function __construct(

View file

@ -17,14 +17,8 @@ class EntryDeletionRepository extends ServiceEntityRepository
/** /**
* Find deletions for a specific user since a given date. The result is paginated. * 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') $qb = $this->createQueryBuilder('de')
->where('de.user = :userId')->setParameter('userId', $userId) ->where('de.user = :userId')->setParameter('userId', $userId)

View file

@ -12,7 +12,7 @@ use Wallabag\Repository\EntryDeletionRepository;
/** /**
* Test the purge entry deletions command. * Test the purge entry deletions command.
* *
* The fixtures set up the following entry deletions: * The fixtures set up the following entry deletions:
* - Admin user: 1 deletion from 4 days ago (entry_id: 1004) * - Admin user: 1 deletion from 4 days ago (entry_id: 1004)
* - Admin user: 1 deletion from 1 day ago (entry_id: 1001) * - Admin user: 1 deletion from 1 day ago (entry_id: 1001)

View file

@ -4,12 +4,12 @@ namespace Tests\Wallabag\Controller\Api;
/** /**
* Test the entry deletion REST API endpoints. * Test the entry deletion REST API endpoints.
* *
* The fixtures set up the following entry deletions: * The fixtures set up the following entry deletions:
* - Admin user: 1 deletion from 4 days ago (entry_id: 1004) * - Admin user: 1 deletion from 4 days ago (entry_id: 1004)
* - Admin user: 1 deletion from 1 day ago (entry_id: 1001) * - Admin user: 1 deletion from 1 day ago (entry_id: 1001)
* - Bob user: 1 deletion from 3 days ago (entry_id: 1003) * - Bob user: 1 deletion from 3 days ago (entry_id: 1003)
* *
* The logged in user is admin. * The logged in user is admin.
*/ */
class EntryDeletionRestControllerTest extends WallabagApiTestCase class EntryDeletionRestControllerTest extends WallabagApiTestCase
@ -21,7 +21,7 @@ class EntryDeletionRestControllerTest extends WallabagApiTestCase
$content = json_decode($this->client->getResponse()->getContent(), true); $content = json_decode($this->client->getResponse()->getContent(), true);
// check that only the items for the current user are returned // 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 // validate the deletion schema on the first item
$deletionData = $content['_embedded']['items'][0]; $deletionData = $content['_embedded']['items'][0];