1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-06-27 16:36:00 +00:00

Merge pull request #8121 from wallabag/clean-phpstan-baseline

Clean PHPStan baseline
This commit is contained in:
Yassine Guedidi 2025-04-05 18:11:11 +02:00 committed by GitHub
commit d4fbb80dd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 73 additions and 85 deletions

View file

@ -1,66 +0,0 @@
parameters:
ignoreErrors:
-
message: "#^Method Wallabag\\\\Controller\\\\AnnotationController\\:\\:postAnnotationAction\\(\\) should return Symfony\\\\Component\\\\HttpFoundation\\\\JsonResponse but returns Symfony\\\\Component\\\\Form\\\\FormInterface\\<mixed\\>\\.$#"
count: 1
path: src/Controller/AnnotationController.php
-
message: "#^Method Wallabag\\\\Controller\\\\AnnotationController\\:\\:putAnnotationAction\\(\\) should return Symfony\\\\Component\\\\HttpFoundation\\\\JsonResponse but returns Symfony\\\\Component\\\\Form\\\\FormInterface\\<mixed\\>\\.$#"
count: 1
path: src/Controller/AnnotationController.php
-
message: "#^Method FOS\\\\UserBundle\\\\Model\\\\UserManagerInterface\\:\\:updateUser\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 6
path: src/Controller/ConfigController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#"
count: 1
path: src/Controller/Import/BrowserController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setUser\\(\\)\\.$#"
count: 1
path: src/Controller/Import/BrowserController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#"
count: 1
path: src/Controller/Import/HtmlController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setUser\\(\\)\\.$#"
count: 1
path: src/Controller/Import/HtmlController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#"
count: 1
path: src/Controller/Import/WallabagController.php
-
message: "#^Call to an undefined method Wallabag\\\\Import\\\\ImportInterface\\:\\:setUser\\(\\)\\.$#"
count: 1
path: src/Controller/Import/WallabagController.php
-
message: "#^Call to an undefined method Spiriit\\\\Bundle\\\\FormFilterBundle\\\\Filter\\\\Query\\\\QueryInterface\\:\\:getExpressionBuilder\\(\\)\\.$#"
count: 1
path: src/Event/Subscriber/CustomDoctrineORMSubscriber.php
-
message: "#^Call to an undefined method Spiriit\\\\Bundle\\\\FormFilterBundle\\\\Filter\\\\Query\\\\QueryInterface\\:\\:getExpr\\(\\)\\.$#"
count: 10
path: src/Form/Type/EntryFilterType.php
-
message: "#^Call to an undefined method Scheb\\\\TwoFactorBundle\\\\Model\\\\Email\\\\TwoFactorInterface\\:\\:getName\\(\\)\\.$#"
count: 2
path: src/Mailer/AuthCodeMailer.php
-
message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#"
count: 1
path: tests/Controller/FeedControllerTest.php

View file

@ -85,7 +85,7 @@ class AnnotationController extends AbstractFOSRestController
return JsonResponse::fromJsonString($json); return JsonResponse::fromJsonString($json);
} }
return $form; return new JsonResponse(status: 400);
} }
/** /**
@ -118,7 +118,7 @@ class AnnotationController extends AbstractFOSRestController
return JsonResponse::fromJsonString($json); return JsonResponse::fromJsonString($json);
} }
return $form; return new JsonResponse(status: 400);
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
throw new NotFoundHttpException($e); throw new NotFoundHttpException($e);
} }

View file

@ -109,7 +109,8 @@ class ConfigController extends AbstractController
$message = 'flashes.config.notice.password_updated'; $message = 'flashes.config.notice.password_updated';
$user->setPlainPassword($pwdForm->get('new_password')->getData()); $user->setPlainPassword($pwdForm->get('new_password')->getData());
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash('notice', $message); $this->addFlash('notice', $message);
@ -124,7 +125,8 @@ class ConfigController extends AbstractController
$userForm->handleRequest($request); $userForm->handleRequest($request);
if ($userForm->isSubmitted() && $userForm->isValid()) { if ($userForm->isSubmitted() && $userForm->isValid()) {
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash( $this->addFlash(
'notice', 'notice',
@ -277,7 +279,8 @@ class ConfigController extends AbstractController
$user = $this->getUser(); $user = $this->getUser();
$user->setEmailTwoFactor(false); $user->setEmailTwoFactor(false);
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash( $this->addFlash(
'notice', 'notice',
@ -305,7 +308,8 @@ class ConfigController extends AbstractController
$user->setBackupCodes(null); $user->setBackupCodes(null);
$user->setEmailTwoFactor(true); $user->setEmailTwoFactor(true);
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash( $this->addFlash(
'notice', 'notice',
@ -332,7 +336,8 @@ class ConfigController extends AbstractController
$user->setGoogleAuthenticatorSecret(''); $user->setGoogleAuthenticatorSecret('');
$user->setBackupCodes(null); $user->setBackupCodes(null);
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash( $this->addFlash(
'notice', 'notice',
@ -370,7 +375,8 @@ class ConfigController extends AbstractController
$user->setBackupCodes($backupCodesHashed); $user->setBackupCodes($backupCodesHashed);
$this->userManager->updateUser($user, true); $this->userManager->updateUser($user);
$this->entityManager->flush();
$this->addFlash( $this->addFlash(
'notice', 'notice',

View file

@ -4,6 +4,7 @@ namespace Wallabag\Event\Subscriber;
use Spiriit\Bundle\FormFilterBundle\Event\GetFilterConditionEvent; use Spiriit\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Spiriit\Bundle\FormFilterBundle\Event\Subscriber\DoctrineORMSubscriber; use Spiriit\Bundle\FormFilterBundle\Event\Subscriber\DoctrineORMSubscriber;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
@ -14,7 +15,11 @@ class CustomDoctrineORMSubscriber extends DoctrineORMSubscriber implements Event
{ {
public function filterDateRange(GetFilterConditionEvent $event) public function filterDateRange(GetFilterConditionEvent $event)
{ {
$expr = $event->getFilterQuery()->getExpressionBuilder(); $filterQuery = $event->getFilterQuery();
\assert($filterQuery instanceof ORMQuery);
$expr = $filterQuery->getExpressionBuilder();
$values = $event->getValues(); $values = $event->getValues();
$value = $values['value']; $value = $values['value'];

View file

@ -2,6 +2,7 @@
namespace Wallabag\Form\Type; namespace Wallabag\Form\Type;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery;
use Spiriit\Bundle\FormFilterBundle\Filter\FilterOperands; use Spiriit\Bundle\FormFilterBundle\Filter\FilterOperands;
use Spiriit\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType; use Spiriit\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType;
use Spiriit\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; use Spiriit\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType;
@ -57,6 +58,8 @@ class EntryFilterType extends AbstractType
return; return;
} }
\assert($filterQuery instanceof ORMQuery);
$min = (int) ($lower * $user->getConfig()->getReadingSpeed() / 200); $min = (int) ($lower * $user->getConfig()->getReadingSpeed() / 200);
$max = (int) ($upper * $user->getConfig()->getReadingSpeed() / 200); $max = (int) ($upper * $user->getConfig()->getReadingSpeed() / 200);
@ -98,6 +101,9 @@ class EntryFilterType extends AbstractType
if (empty($value) || \strlen($value) <= 2) { if (empty($value) || \strlen($value) <= 2) {
return false; return false;
} }
\assert($filterQuery instanceof ORMQuery);
$expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%'))); $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%')));
return $filterQuery->createCondition($expression); return $filterQuery->createCondition($expression);
@ -114,6 +120,8 @@ class EntryFilterType extends AbstractType
return false; return false;
} }
\assert($filterQuery instanceof ORMQuery);
$paramName = \sprintf('%s', str_replace('.', '_', $field)); $paramName = \sprintf('%s', str_replace('.', '_', $field));
$expression = $filterQuery->getExpr()->eq($field, ':' . $paramName); $expression = $filterQuery->getExpr()->eq($field, ':' . $paramName);
$parameters = [$paramName => $value]; $parameters = [$paramName => $value];
@ -143,6 +151,8 @@ class EntryFilterType extends AbstractType
return false; return false;
} }
\assert($filterQuery instanceof ORMQuery);
$expression = $filterQuery->getExpr()->eq('e.isArchived', 'false'); $expression = $filterQuery->getExpr()->eq('e.isArchived', 'false');
return $filterQuery->createCondition($expression); return $filterQuery->createCondition($expression);
@ -170,6 +180,8 @@ class EntryFilterType extends AbstractType
return false; return false;
} }
\assert($filterQuery instanceof ORMQuery);
$expression = $filterQuery->getExpr()->isNotNull($field); $expression = $filterQuery->getExpr()->isNotNull($field);
return $filterQuery->createCondition($expression); return $filterQuery->createCondition($expression);
@ -182,6 +194,8 @@ class EntryFilterType extends AbstractType
return false; return false;
} }
\assert($filterQuery instanceof ORMQuery);
// is_public isn't a real field // is_public isn't a real field
// we should use the "uid" field to determine if the entry has been made public // we should use the "uid" field to determine if the entry has been made public
$expression = $filterQuery->getExpr()->isNotNull($values['alias'] . '.uid'); $expression = $filterQuery->getExpr()->isNotNull($values['alias'] . '.uid');

View file

@ -65,7 +65,7 @@ abstract class AbstractImport implements ImportInterface
* *
* @param bool $markAsRead * @param bool $markAsRead
*/ */
public function setMarkAsRead($markAsRead) public function setMarkAsRead($markAsRead): static
{ {
$this->markAsRead = $markAsRead; $this->markAsRead = $markAsRead;
@ -101,6 +101,11 @@ abstract class AbstractImport implements ImportInterface
]; ];
} }
public function setFilepath($filepath): static
{
return $this;
}
/** /**
* Parse one entry. * Parse one entry.
* *

View file

@ -53,7 +53,7 @@ abstract class BrowserImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -28,7 +28,7 @@ class DeliciousImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -64,7 +64,7 @@ abstract class HtmlImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -3,6 +3,7 @@
namespace Wallabag\Import; namespace Wallabag\Import;
use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareInterface;
use Wallabag\Entity\User;
interface ImportInterface extends LoggerAwareInterface interface ImportInterface extends LoggerAwareInterface
{ {
@ -42,4 +43,24 @@ interface ImportInterface extends LoggerAwareInterface
* @return array * @return array
*/ */
public function getSummary(); public function getSummary();
/**
* Set current user.
* Could the current *connected* user or one retrieve by the consumer.
*/
public function setUser(User $user);
/**
* Set file path to the json file.
*
* @param string $filepath
*/
public function setFilepath($filepath): static;
/**
* Set whether articles must be all marked as read.
*
* @param bool $markAsRead
*/
public function setMarkAsRead($markAsRead): static;
} }

View file

@ -28,7 +28,7 @@ class InstapaperImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -28,7 +28,7 @@ class OmnivoreImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -28,7 +28,7 @@ class PinboardImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -28,7 +28,7 @@ class ReadabilityImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -67,7 +67,7 @@ abstract class WallabagImport extends AbstractImport
* *
* @param string $filepath * @param string $filepath
*/ */
public function setFilepath($filepath) public function setFilepath($filepath): static
{ {
$this->filepath = $filepath; $this->filepath = $filepath;

View file

@ -8,6 +8,7 @@ use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address; use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Email;
use Twig\Environment; use Twig\Environment;
use Wallabag\Entity\User;
/** /**
* Custom mailer for TwoFactorBundle email. * Custom mailer for TwoFactorBundle email.
@ -69,6 +70,8 @@ class AuthCodeMailer implements AuthCodeMailerInterface
*/ */
public function sendAuthCode(TwoFactorInterface $user): void public function sendAuthCode(TwoFactorInterface $user): void
{ {
\assert($user instanceof User);
$template = $this->twig->load('TwoFactor/email_auth_code.html.twig'); $template = $this->twig->load('TwoFactor/email_auth_code.html.twig');
$subject = $template->renderBlock('subject', []); $subject = $template->renderBlock('subject', []);

View file

@ -45,7 +45,7 @@ class FeedControllerTest extends WallabagTestCase
} }
$this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length); $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="self"]')->length);
$this->assertStringContainsString($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->getAttribute('href')); $this->assertStringContainsString($type, $xpath->query('/a:feed/a:link[@rel="self"]')->item(0)->attributes['href']->value);
$this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length); $this->assertSame(1, $xpath->query('/a:feed/a:link[@rel="last"]')->length);