mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
round of make phpstan fix-cs
This commit is contained in:
parent
1883ff1380
commit
1fb17a17b6
10 changed files with 29 additions and 43 deletions
|
@ -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 <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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -28,6 +28,7 @@ class EntryDeletionExpirationConfig
|
|||
public function setExpirationDays(int $days): self
|
||||
{
|
||||
$this->expirationDays = $days;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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')]
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue