Merge pull request #6815 from yguedidi/phpstan-level-3

PHPStan level 3
This commit is contained in:
Jérémy Benoist 2023-08-21 15:27:37 +02:00 committed by GitHub
commit c12239c4f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 86 additions and 74 deletions

View file

@ -1,10 +1,25 @@
parameters:
ignoreErrors:
-
message: "#^Method Wallabag\\\\AnnotationBundle\\\\Controller\\\\WallabagAnnotationController\\:\\:postAnnotationAction\\(\\) should return Symfony\\\\Component\\\\HttpFoundation\\\\JsonResponse but returns Symfony\\\\Component\\\\Form\\\\FormInterface\\<mixed\\>\\.$#"
count: 1
path: src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php
-
message: "#^Method Wallabag\\\\AnnotationBundle\\\\Controller\\\\WallabagAnnotationController\\:\\:putAnnotationAction\\(\\) should return Symfony\\\\Component\\\\HttpFoundation\\\\JsonResponse but returns Symfony\\\\Component\\\\Form\\\\FormInterface\\<mixed\\>\\.$#"
count: 1
path: src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php
-
message: "#^Call to an undefined method Wallabag\\\\CoreBundle\\\\Entity\\\\RuleInterface\\:\\:getConfig\\(\\)\\.$#"
count: 1
path: src/Wallabag/CoreBundle/Controller/ConfigController.php
-
message: "#^Method FOS\\\\UserBundle\\\\Model\\\\UserManagerInterface\\:\\:updateUser\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 7
path: src/Wallabag/CoreBundle/Controller/ConfigController.php
-
message: "#^Call to an undefined method Lexik\\\\Bundle\\\\FormFilterBundle\\\\Filter\\\\Query\\\\QueryInterface\\:\\:getExpressionBuilder\\(\\)\\.$#"
count: 1
@ -40,27 +55,12 @@ parameters:
count: 2
path: src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
-
message: "#^PHPDoc type Symfony\\\\Component\\\\Mailer\\\\MailerInterface of property Wallabag\\\\UserBundle\\\\Mailer\\\\UserMailer\\:\\:\\$mailer is not covariant with PHPDoc type Swift_Mailer of overridden property FOS\\\\UserBundle\\\\Mailer\\\\TwigSwiftMailer\\:\\:\\$mailer\\.$#"
count: 1
path: src/Wallabag/UserBundle/Mailer/UserMailer.php
-
message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#"
count: 1
path: tests/Wallabag/CoreBundle/Controller/FeedControllerTest.php
-
message: "#^Call to method generate\\(\\) on an unknown class PHPUnit_Framework_MockObject_MockObject\\.$#"
count: 2
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
-
message: "#^Property Tests\\\\Wallabag\\\\CoreBundle\\\\Helper\\\\RedirectTest\\:\\:\\$routerMock has unknown class PHPUnit_Framework_MockObject_MockObject as its type\\.$#"
count: 1
path: tests/Wallabag/CoreBundle/Helper/RedirectTest.php
-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch()#"
count: 15
path: src/*
-
message: "#^Method FOS\\\\UserBundle\\\\Model\\\\UserManagerInterface\\:\\:updateUser()#"
count: 7
path: src/Wallabag/CoreBundle/Controller/ConfigController.php

View file

@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon
parameters:
level: 2
level: 3
paths:
- src
- tests
@ -14,3 +14,6 @@ parameters:
- vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php
inferPrivatePropertyTypeFromConstructor: true
ignoreErrors:
- "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"

View file

@ -4,8 +4,8 @@ namespace Wallabag\ApiBundle\Controller;
use Nelmio\ApiDocBundle\Annotation\Operation;
use OpenApi\Annotations as OA;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Wallabag\AnnotationBundle\Entity\Annotation;
use Wallabag\CoreBundle\Entity\Entry;
@ -36,7 +36,7 @@ class AnnotationRestController extends WallabagRestController
*
* @Route("/api/annotations/{entry}.{_format}", methods={"GET"}, name="api_get_annotations", defaults={"_format": "json"})
*
* @return JsonResponse
* @return Response
*/
public function getAnnotationsAction(Entry $entry)
{
@ -102,7 +102,7 @@ class AnnotationRestController extends WallabagRestController
*
* @Route("/api/annotations/{entry}.{_format}", methods={"POST"}, name="api_post_annotation", defaults={"_format": "json"})
*
* @return JsonResponse
* @return Response
*/
public function postAnnotationAction(Request $request, Entry $entry)
{
@ -138,7 +138,7 @@ class AnnotationRestController extends WallabagRestController
*
* @Route("/api/annotations/{annotation}.{_format}", methods={"PUT"}, name="api_put_annotation", defaults={"_format": "json"})
*
* @return JsonResponse
* @return Response
*/
public function putAnnotationAction(int $annotation, Request $request)
{
@ -174,7 +174,7 @@ class AnnotationRestController extends WallabagRestController
*
* @Route("/api/annotations/{annotation}.{_format}", methods={"DELETE"}, name="api_delete_annotation", defaults={"_format": "json"})
*
* @return JsonResponse
* @return Response
*/
public function deleteAnnotationAction(int $annotation)
{

View file

@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -138,7 +139,7 @@ class IgnoreOriginInstanceRuleController extends AbstractController
*
* @param IgnoreOriginInstanceRule $ignoreOriginInstanceRule The ignore origin instance rule entity
*
* @return Form The form
* @return FormInterface The form
*/
private function createDeleteForm(IgnoreOriginInstanceRule $ignoreOriginInstanceRule)
{

View file

@ -6,6 +6,7 @@ use Craue\ConfigBundle\Util\Config;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -173,7 +174,7 @@ class SiteCredentialController extends AbstractController
*
* @param SiteCredential $siteCredential The site credential entity
*
* @return Form The form
* @return FormInterface The form
*/
private function createDeleteForm(SiteCredential $siteCredential)
{

View file

@ -132,12 +132,16 @@ class Config
private $user;
/**
* @var ArrayCollection<TaggingRule>
*
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"})
* @ORM\OrderBy({"id" = "ASC"})
*/
private $taggingRules;
/**
@var ArrayCollection<IgnoreOriginUserRule>
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"})
* @ORM\OrderBy({"id" = "ASC"})
*/
@ -371,12 +375,9 @@ class Config
return $this;
}
/**
* @return bool
*/
public function getDisplayThumbnails(): ?bool
public function getDisplayThumbnails(): bool
{
return $this->displayThumbnails;
return (bool) $this->displayThumbnails;
}
/**
@ -384,7 +385,7 @@ class Config
*/
public function setDisplayThumbnails(bool $displayThumbnails)
{
$this->displayThumbnails = $displayThumbnails;
$this->displayThumbnails = $displayThumbnails ? 1 : 0;
return $this;
}

View file

@ -55,7 +55,7 @@ class Entry
private $id;
/**
* @var string
* @var string|null
*
* @ORM\Column(name="uid", type="string", length=23, nullable=true)
*
@ -132,7 +132,7 @@ class Entry
private $isArchived = false;
/**
* @var \DateTime
* @var \DateTimeInterface
*
* @ORM\Column(name="archived_at", type="datetime", nullable=true)
*
@ -161,7 +161,7 @@ class Entry
private $content;
/**
* @var \DateTime
* @var \DateTimeInterface
*
* @ORM\Column(name="created_at", type="datetime")
*
@ -170,7 +170,7 @@ class Entry
private $createdAt;
/**
* @var \DateTime
* @var \DateTimeInterface
*
* @ORM\Column(name="updated_at", type="datetime")
*
@ -179,7 +179,7 @@ class Entry
private $updatedAt;
/**
* @var \DateTime
* @var \DateTimeInterface
*
* @ORM\Column(name="published_at", type="datetime", nullable=true)
*
@ -197,7 +197,7 @@ class Entry
private $publishedBy;
/**
* @var \DateTime
* @var \DateTimeInterface
*
* @ORM\Column(name="starred_at", type="datetime", nullable=true)
*
@ -400,7 +400,7 @@ class Entry
}
/**
* @return \DateTime|null
* @return \DateTimeInterface|null
*/
public function getArchivedAt()
{
@ -408,7 +408,7 @@ class Entry
}
/**
* @param \DateTime|null $archivedAt
* @param \DateTimeInterface|null $archivedAt
*
* @return Entry
*/
@ -482,7 +482,7 @@ class Entry
public function toggleStar()
{
$this->isStarred = $this->isStarred() ^ 1;
$this->isStarred = !$this->isStarred();
return $this;
}
@ -560,7 +560,7 @@ class Entry
}
/**
* @return \DateTime
* @return \DateTimeInterface
*/
public function getCreatedAt()
{
@ -568,7 +568,7 @@ class Entry
}
/**
* @return \DateTime
* @return \DateTimeInterface
*/
public function getUpdatedAt()
{
@ -576,7 +576,7 @@ class Entry
}
/**
* @return \DateTime|null
* @return \DateTimeInterface|null
*/
public function getStarredAt()
{
@ -584,7 +584,7 @@ class Entry
}
/**
* @param \DateTime|null $starredAt
* @param \DateTimeInterface|null $starredAt
*
* @return Entry
*/
@ -881,7 +881,7 @@ class Entry
}
/**
* @return \DateTime
* @return \DateTimeInterface
*/
public function getPublishedAt()
{
@ -891,7 +891,7 @@ class Entry
/**
* @return Entry
*/
public function setPublishedAt(\DateTime $publishedAt)
public function setPublishedAt(\DateTimeInterface $publishedAt)
{
$this->publishedAt = $publishedAt;

View file

@ -49,7 +49,7 @@ class StringToListTransformer implements DataTransformerInterface
public function reverseTransform($string)
{
if (null === $string) {
return;
return null;
}
return array_values(array_filter(array_map('trim', explode($this->separator, $string))));

View file

@ -3,6 +3,7 @@
namespace Wallabag\CoreBundle\Helper;
use Pagerfanta\Adapter\AdapterInterface;
use Pagerfanta\Adapter\NullAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Wallabag\UserBundle\Entity\User;
@ -19,7 +20,7 @@ class PreparePagerForEntries
/**
* @param User $user If user isn't logged in, we can force it (like for feed)
*
* @return Pagerfanta|null
* @return Pagerfanta
*/
public function prepare(AdapterInterface $adapter, User $user = null)
{
@ -28,7 +29,7 @@ class PreparePagerForEntries
}
if (!$user instanceof User) {
return;
return new Pagerfanta(new NullAdapter());
}
$entries = new Pagerfanta($adapter);

View file

@ -2,6 +2,7 @@
namespace Wallabag\CoreBundle\Helper;
use Doctrine\Common\Collections\ArrayCollection;
use Psr\Log\LoggerInterface;
use RulerZ\RulerZ;
use Wallabag\CoreBundle\Entity\Entry;
@ -120,7 +121,7 @@ class RuleBasedTagger
/**
* Retrieves the tagging rules for a given user.
*
* @return array<TaggingRule>
* @return ArrayCollection<TaggingRule>
*/
private function getRulesForUser(User $user)
{

View file

@ -429,7 +429,7 @@ class EntryRepository extends ServiceEntityRepository
/**
* Find all entries which have an empty value for hash.
*
* @return Entry|false
* @return Entry[]
*/
public function findByEmptyHashedUrlAndUserId(int $userId)
{

View file

@ -42,7 +42,7 @@ class SiteCredentialRepository extends ServiceEntityRepository
->getOneOrNullResult();
if (null === $res) {
return;
return null;
}
// decrypt user & password before returning them

View file

@ -145,7 +145,7 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface
$user = $this->tokenStorage->getToken() ? $this->tokenStorage->getToken()->getUser() : null;
if (!$user instanceof User) {
return 0;
return '';
}
$query = $this->entryRepository->getBuilderForArchiveByUser($user->getId())

View file

@ -107,7 +107,7 @@ abstract class AbstractImport implements ImportInterface
/**
* Parse one entry.
*
* @return Entry
* @return Entry|null
*/
abstract public function parseEntry(array $importedEntry);

View file

@ -81,28 +81,28 @@ abstract class BrowserImport extends AbstractImport
if ($this->producer) {
$this->parseEntriesForProducer($importedEntry);
return;
return null;
}
$this->parseEntries($importedEntry);
return;
return null;
}
if (\array_key_exists('children', $importedEntry)) {
if ($this->producer) {
$this->parseEntriesForProducer($importedEntry['children']);
return;
return null;
}
$this->parseEntries($importedEntry['children']);
return;
return null;
}
if (!\array_key_exists('uri', $importedEntry) && !\array_key_exists('url', $importedEntry)) {
return;
return null;
}
$url = \array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
@ -114,7 +114,7 @@ abstract class BrowserImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$data = $this->prepareEntry($importedEntry);

View file

@ -104,7 +104,7 @@ class DeliciousImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$data = [

View file

@ -132,7 +132,7 @@ class InstapaperImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$entry = new Entry($this->user);

View file

@ -104,7 +104,7 @@ class PinboardImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$data = [

View file

@ -186,7 +186,7 @@ class PocketImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$entry = new Entry($this->user);

View file

@ -104,7 +104,7 @@ class ReadabilityImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$data = [

View file

@ -110,7 +110,7 @@ abstract class WallabagImport extends AbstractImport
if (false !== $existingEntry) {
++$this->skippedEntries;
return;
return null;
}
$data = $this->prepareEntry($importedEntry);

View file

@ -13,6 +13,7 @@ use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -184,7 +185,7 @@ class ManageController extends AbstractController
*
* @param User $user The User entity
*
* @return Form The form
* @return FormInterface The form
*/
private function createDeleteForm(User $user)
{

View file

@ -673,7 +673,7 @@ class EntryControllerTest extends WallabagCoreTestCase
->getRepository(Entry::class)
->findOneById($entry->getId());
$this->assertSame(1, $res->isStarred());
$this->assertTrue($res->isStarred());
}
public function testDelete()
@ -1748,14 +1748,14 @@ class EntryControllerTest extends WallabagCoreTestCase
->getRepository(Entry::class)
->find($entry1->getId());
$this->assertSame(1, $res->isStarred());
$this->assertTrue($res->isStarred());
$res = $client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->find($entry2->getId());
$this->assertSame(1, $res->isStarred());
$this->assertTrue($res->isStarred());
// Mass actions : tag
$client->request('POST', '/mass', [

View file

@ -2,6 +2,7 @@
namespace Tests\Wallabag\CoreBundle\Helper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
@ -12,7 +13,7 @@ use Wallabag\UserBundle\Entity\User;
class RedirectTest extends TestCase
{
/** @var \PHPUnit_Framework_MockObject_MockObject */
/** @var Router&MockObject */
private $routerMock;
/** @var Redirect */

View file

@ -138,6 +138,8 @@ abstract class WallabagCoreTestCase extends WebTestCase
$token = static::$kernel->getContainer()->get(TokenStorageInterface::class)->getToken();
if (null !== $token) {
\assert($token->getUser() instanceof User);
return $token->getUser();
}