diff --git a/phpstan.neon b/phpstan.neon
index ad809211c..f45cd1016 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon
parameters:
- level: 4
+ level: 5
paths:
- src
- tests
diff --git a/src/Command/Import/ImportCommand.php b/src/Command/Import/ImportCommand.php
index 2f5b6ba18..33436e059 100644
--- a/src/Command/Import/ImportCommand.php
+++ b/src/Command/Import/ImportCommand.php
@@ -96,6 +96,7 @@ class ImportCommand extends Command
$this->tokenStorage->setToken($token);
$user = $this->tokenStorage->getToken()->getUser();
+ \assert($user instanceof User);
$import = match ($input->getOption('importer')) {
'v2' => $this->wallabagV2Import,
diff --git a/src/Controller/Api/EntryRestController.php b/src/Controller/Api/EntryRestController.php
index ae28f236a..52e27ebc3 100644
--- a/src/Controller/Api/EntryRestController.php
+++ b/src/Controller/Api/EntryRestController.php
@@ -308,10 +308,10 @@ class EntryRestController extends WallabagRestController
$isNotParsed = (null === $request->query->get('notParsed')) ? null : (bool) $request->query->get('notParsed');
$sort = strtolower($request->query->get('sort', 'created'));
$order = strtolower($request->query->get('order', 'desc'));
- $page = (int) $request->query->get('page', 1);
- $perPage = (int) $request->query->get('perPage', 30);
+ $page = $request->query->getInt('page', 1);
+ $perPage = $request->query->getInt('perPage', 30);
$tags = \is_array($request->query->all()['tags'] ?? '') ? '' : (string) $request->query->get('tags', '');
- $since = $request->query->get('since', 0);
+ $since = $request->query->getInt('since');
$detail = strtolower($request->query->get('detail', 'full'));
$domainName = (null === $request->query->get('domain_name')) ? '' : (string) $request->query->get('domain_name');
$httpStatus = (!\array_key_exists((int) $request->query->get('http_status'), Response::$statusTexts)) ? null : (int) $request->query->get('http_status');
diff --git a/src/Controller/Api/SearchRestController.php b/src/Controller/Api/SearchRestController.php
index 98a3f6c81..93ee3f7ad 100644
--- a/src/Controller/Api/SearchRestController.php
+++ b/src/Controller/Api/SearchRestController.php
@@ -62,8 +62,8 @@ class SearchRestController extends WallabagRestController
public function getSearchAction(Request $request, EntryRepository $entryRepository)
{
$term = $request->query->get('term');
- $page = (int) $request->query->get('page', 1);
- $perPage = (int) $request->query->get('perPage', 30);
+ $page = $request->query->getInt('page', 1);
+ $perPage = $request->query->getInt('perPage', 30);
$qb = $entryRepository->getBuilderForSearchByUser(
$this->getUser()->getId(),
diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php
index 197d504a5..39b4e48ad 100644
--- a/src/Controller/ConfigController.php
+++ b/src/Controller/ConfigController.php
@@ -647,7 +647,7 @@ class ConfigController extends AbstractController
}
$user = $this->getUser();
- $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
+ $user->getConfig()->setListMode((int) !$user->getConfig()->getListMode());
$this->entityManager->persist($user);
$this->entityManager->flush();
diff --git a/src/Controller/EntryController.php b/src/Controller/EntryController.php
index 658bf57c5..ca34e0dd1 100644
--- a/src/Controller/EntryController.php
+++ b/src/Controller/EntryController.php
@@ -102,7 +102,7 @@ class EntryController extends AbstractController
if (isset($values['entry-checkbox'])) {
foreach ($values['entry-checkbox'] as $id) {
/** @var Entry * */
- $entry = $this->entryRepository->findById((int) $id)[0];
+ $entry = $this->entryRepository->findById([(int) $id])[0];
if (!$this->security->isGranted('EDIT', $entry)) {
throw $this->createAccessDeniedException('You can not access this entry.');
diff --git a/src/Controller/ExportController.php b/src/Controller/ExportController.php
index af4f813f8..7998d54a8 100644
--- a/src/Controller/ExportController.php
+++ b/src/Controller/ExportController.php
@@ -54,7 +54,7 @@ class ExportController extends AbstractController
if ('same_domain' === $category) {
$entries = $entryRepository->getBuilderForSameDomainByUser(
$this->getUser()->getId(),
- $request->query->get('entry')
+ $request->query->getInt('entry')
)->getQuery()
->getResult();
diff --git a/src/Entity/Config.php b/src/Entity/Config.php
index 5733945af..780f14dd8 100644
--- a/src/Entity/Config.php
+++ b/src/Entity/Config.php
@@ -238,7 +238,7 @@ class Config
/**
* Set feed Token.
*
- * @param string $feedToken
+ * @param string|null $feedToken
*
* @return Config
*/
@@ -252,7 +252,7 @@ class Config
/**
* Get feedToken.
*
- * @return string
+ * @return string|null
*/
public function getFeedToken()
{
diff --git a/src/Entity/Entry.php b/src/Entity/Entry.php
index 8554b26b7..0824b1c4f 100644
--- a/src/Entity/Entry.php
+++ b/src/Entity/Entry.php
@@ -383,7 +383,7 @@ class Entry
public function toggleArchive()
{
- $this->updateArchived($this->isArchived() ^ 1);
+ $this->updateArchived((bool) ($this->isArchived() ^ 1));
return $this;
}
diff --git a/src/Event/Listener/CreateConfigListener.php b/src/Event/Listener/CreateConfigListener.php
index e7af5a15b..b4df73042 100644
--- a/src/Event/Listener/CreateConfigListener.php
+++ b/src/Event/Listener/CreateConfigListener.php
@@ -8,6 +8,7 @@ use FOS\UserBundle\FOSUserEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Wallabag\Entity\Config;
+use Wallabag\Entity\User;
/**
* This listener will create the associated configuration when a user register.
@@ -48,7 +49,10 @@ class CreateConfigListener implements EventSubscriberInterface
$language = $session->get('_locale', $this->language);
}
- $config = new Config($event->getUser());
+ $user = $event->getUser();
+ \assert($user instanceof User);
+
+ $config = new Config($user);
$config->setItemsPerPage($this->itemsOnPage);
$config->setFeedLimit($this->feedLimit);
$config->setLanguage($language);
diff --git a/src/Helper/DownloadImages.php b/src/Helper/DownloadImages.php
index e46f8289e..d5a00b0f8 100644
--- a/src/Helper/DownloadImages.php
+++ b/src/Helper/DownloadImages.php
@@ -208,7 +208,7 @@ class DownloadImages
case 'png':
imagealphablending($im, false);
imagesavealpha($im, true);
- imagepng($im, $localPath, ceil(self::REGENERATE_PICTURES_QUALITY / 100 * 9));
+ imagepng($im, $localPath, (int) ceil(self::REGENERATE_PICTURES_QUALITY / 100 * 9));
$this->logger->debug('DownloadImages: Re-creating png');
break;
case 'webp':
@@ -254,7 +254,7 @@ class DownloadImages
*/
public function getRelativePath($entryId, $createFolder = true)
{
- $hashId = hash('crc32', $entryId);
+ $hashId = hash('crc32', (string) $entryId);
$relativePath = $hashId[0] . '/' . $hashId[1] . '/' . $hashId;
$folderPath = $this->baseFolder . '/' . $relativePath;
diff --git a/src/Helper/EntriesExport.php b/src/Helper/EntriesExport.php
index 64360c3e2..db57ff31b 100644
--- a/src/Helper/EntriesExport.php
+++ b/src/Helper/EntriesExport.php
@@ -285,13 +285,13 @@ class EntriesExport
'
' . $this->translator->trans('entry.metadata.added_on') . '' . $entry->getCreatedAt()->format('Y-m-d') . '' .
'' . $this->translator->trans('entry.metadata.address') . '' . $entry->getUrl() . '' .
'';
- $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
+ $pdf->writeHTMLCell(0, 0, null, null, $html, 0, 1);
$pdf->AddPage();
$html = '' . $entry->getTitle() . '
';
$html .= $entry->getContent();
- $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
+ $pdf->writeHTMLCell(0, 0, null, null, $html, 0, 1);
}
/*
@@ -300,7 +300,7 @@ class EntriesExport
$pdf->AddPage();
$html = $this->getExportInformation('tcpdf');
- $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
+ $pdf->writeHTMLCell(0, 0, null, null, $html, 0, 1);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
diff --git a/src/Repository/ConfigRepository.php b/src/Repository/ConfigRepository.php
index 7c86994bf..60ec164b7 100644
--- a/src/Repository/ConfigRepository.php
+++ b/src/Repository/ConfigRepository.php
@@ -5,9 +5,10 @@ namespace Wallabag\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Wallabag\Entity\Config;
+use Wallabag\Entity\User;
/**
- * @method Config|null findOneByUser(int $userId)
+ * @method Config|null findOneByUser(User $user)
*/
class ConfigRepository extends ServiceEntityRepository
{
diff --git a/src/Repository/EntryRepository.php b/src/Repository/EntryRepository.php
index ded1e2d44..6c48d5b3e 100644
--- a/src/Repository/EntryRepository.php
+++ b/src/Repository/EntryRepository.php
@@ -13,7 +13,7 @@ use Wallabag\Entity\Tag;
use Wallabag\Helper\UrlHasher;
/**
- * @method Entry[] findById(int $id)
+ * @method Entry[] findById(int[] $id)
* @method Entry|null findOneByUser(int $userId)
*/
class EntryRepository extends ServiceEntityRepository
@@ -171,9 +171,9 @@ class EntryRepository extends ServiceEntityRepository
/**
* Retrieves entries filtered with a search term for a user.
*
- * @param int $userId
- * @param string $term
- * @param string $currentRoute
+ * @param int $userId
+ * @param string $term
+ * @param 'starred'|'unread'|'homepage'|'archive'|null $currentRoute
*
* @return QueryBuilder
*/
diff --git a/src/Repository/SiteCredentialRepository.php b/src/Repository/SiteCredentialRepository.php
index 3e1d1a357..3a2d982aa 100644
--- a/src/Repository/SiteCredentialRepository.php
+++ b/src/Repository/SiteCredentialRepository.php
@@ -5,12 +5,13 @@ namespace Wallabag\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Wallabag\Entity\SiteCredential;
+use Wallabag\Entity\User;
use Wallabag\Helper\CryptoProxy;
/**
* SiteCredentialRepository.
*
- * @method SiteCredential[] findByUser(int $userId)
+ * @method SiteCredential[] findByUser(User $user)
*/
class SiteCredentialRepository extends ServiceEntityRepository
{
diff --git a/tests/Controller/Api/DeveloperControllerTest.php b/tests/Controller/Api/DeveloperControllerTest.php
index 9df00a823..11d7f3be5 100644
--- a/tests/Controller/Api/DeveloperControllerTest.php
+++ b/tests/Controller/Api/DeveloperControllerTest.php
@@ -5,6 +5,7 @@ namespace Tests\Wallabag\Controller\Api;
use Doctrine\ORM\EntityManagerInterface;
use Tests\Wallabag\WallabagTestCase;
use Wallabag\Entity\Api\Client;
+use Wallabag\Entity\User;
class DeveloperControllerTest extends WallabagTestCase
{
@@ -133,7 +134,10 @@ class DeveloperControllerTest extends WallabagTestCase
$client = $this->getTestClient();
$em = $client->getContainer()->get(EntityManagerInterface::class);
$userManager = static::getContainer()->get('fos_user.user_manager');
+
$user = $userManager->findUserBy(['username' => $username]);
+ \assert($user instanceof User);
+
$apiClient = new Client($user);
$apiClient->setName('My app');
$apiClient->setAllowedGrantTypes($grantTypes);
diff --git a/tests/Controller/Api/UserRestControllerTest.php b/tests/Controller/Api/UserRestControllerTest.php
index 89748efb6..23d8393c6 100644
--- a/tests/Controller/Api/UserRestControllerTest.php
+++ b/tests/Controller/Api/UserRestControllerTest.php
@@ -45,7 +45,7 @@ class UserRestControllerTest extends WallabagApiTestCase
public function testCreateNewUser()
{
- $this->client->getContainer()->get(Config::class)->set('api_user_registration', 1);
+ $this->client->getContainer()->get(Config::class)->set('api_user_registration', '1');
$this->client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
@@ -73,14 +73,14 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
- $this->client->getContainer()->get(Config::class)->set('api_user_registration', 0);
+ $this->client->getContainer()->get(Config::class)->set('api_user_registration', '0');
}
public function testCreateNewUserWithoutAuthentication()
{
// create a new client instead of using $this->client to be sure client isn't authenticated
$client = $this->createUnauthorizedClient();
- $client->getContainer()->get(Config::class)->set('api_user_registration', 1);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '1');
$client->request('PUT', '/api/user.json', [
'username' => 'google',
'password' => 'googlegoogle',
@@ -109,13 +109,13 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
- $client->getContainer()->get(Config::class)->set('api_user_registration', 0);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '0');
}
public function testCreateNewUserWithExistingEmail()
{
$client = $this->createUnauthorizedClient();
- $client->getContainer()->get(Config::class)->set('api_user_registration', 1);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '1');
$client->request('PUT', '/api/user.json', [
'username' => 'admin',
'password' => 'googlegoogle',
@@ -138,13 +138,13 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
- $client->getContainer()->get(Config::class)->set('api_user_registration', 0);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '0');
}
public function testCreateNewUserWithTooShortPassword()
{
$client = $this->createUnauthorizedClient();
- $client->getContainer()->get(Config::class)->set('api_user_registration', 1);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '1');
$client->request('PUT', '/api/user.json', [
'username' => 'facebook',
'password' => 'face',
@@ -162,7 +162,7 @@ class UserRestControllerTest extends WallabagApiTestCase
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
- $client->getContainer()->get(Config::class)->set('api_user_registration', 0);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '0');
}
public function testCreateNewUserWhenRegistrationIsDisabled()
diff --git a/tests/Controller/Api/WallabagApiTestCase.php b/tests/Controller/Api/WallabagApiTestCase.php
index 1037ab4db..e04020a6f 100644
--- a/tests/Controller/Api/WallabagApiTestCase.php
+++ b/tests/Controller/Api/WallabagApiTestCase.php
@@ -3,7 +3,6 @@
namespace Tests\Wallabag\Controller\Api;
use Doctrine\ORM\EntityManagerInterface;
-use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManager;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@@ -17,7 +16,7 @@ abstract class WallabagApiTestCase extends WebTestCase
protected $client;
/**
- * @var UserInterface
+ * @var User
*/
protected $user;
@@ -49,9 +48,12 @@ abstract class WallabagApiTestCase extends WebTestCase
$userManager = $container->get('fos_user.user_manager');
$firewallName = $container->getParameter('fos_user.firewall_name');
- $this->user = $userManager->findUserBy(['username' => 'admin']);
+ $adminUser = $userManager->findUserBy(['username' => 'admin']);
+ \assert($adminUser instanceof User);
- $client->loginUser($this->user, $firewallName);
+ $this->user = $adminUser;
+
+ $client->loginUser($adminUser, $firewallName);
return $client;
}
diff --git a/tests/Controller/Api/WallabagRestControllerTest.php b/tests/Controller/Api/WallabagRestControllerTest.php
index 46d18d325..2a36d46cc 100644
--- a/tests/Controller/Api/WallabagRestControllerTest.php
+++ b/tests/Controller/Api/WallabagRestControllerTest.php
@@ -45,7 +45,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->markTestSkipped('fosuser_registration is not enabled.');
}
- $client->getContainer()->get(Config::class)->set('api_user_registration', 1);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '1');
$client->request('GET', '/api/info');
@@ -53,7 +53,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertTrue($content['allowed_registration']);
- $client->getContainer()->get(Config::class)->set('api_user_registration', 0);
+ $client->getContainer()->get(Config::class)->set('api_user_registration', '0');
$client->request('GET', '/api/info');
diff --git a/tests/Controller/EntryControllerTest.php b/tests/Controller/EntryControllerTest.php
index 908295694..c90b2acac 100644
--- a/tests/Controller/EntryControllerTest.php
+++ b/tests/Controller/EntryControllerTest.php
@@ -32,7 +32,7 @@ class EntryControllerTest extends WallabagTestCase
{
if ($this->downloadImagesEnabled) {
$client = static::createClient();
- $client->getContainer()->get(Config::class)->set('download_images_enabled', 0);
+ $client->getContainer()->get(Config::class)->set('download_images_enabled', '0');
$this->downloadImagesEnabled = false;
}
@@ -689,7 +689,7 @@ class EntryControllerTest extends WallabagTestCase
->getRepository(Entry::class)
->find($entry->getId());
- $this->assertSame(1, $res->isArchived());
+ $this->assertTrue($res->isArchived());
}
public function testToggleStar()
@@ -1400,7 +1400,7 @@ class EntryControllerTest extends WallabagTestCase
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl('https://www.lemonde.fr/incorrect-url/');
- $entry->setHttpStatus(404);
+ $entry->setHttpStatus('404');
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
@@ -1418,12 +1418,12 @@ class EntryControllerTest extends WallabagTestCase
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl($this->url);
- $entry->setHttpStatus(200);
+ $entry->setHttpStatus('200');
$this->getEntityManager()->persist($entry);
$entry = new Entry($this->getLoggedInUser());
$entry->setUrl('http://www.nextinpact.com/news/101235-wallabag-alternative-libre-a-pocket-creuse-petit-a-petit-son-nid.htm');
- $entry->setHttpStatus(200);
+ $entry->setHttpStatus('200');
$this->getEntityManager()->persist($entry);
$this->getEntityManager()->flush();
@@ -1868,14 +1868,14 @@ class EntryControllerTest extends WallabagTestCase
->getRepository(Entry::class)
->find($entry1->getId());
- $this->assertSame(1, $res->isArchived());
+ $this->assertTrue($res->isArchived());
$res = $client->getContainer()
->get(EntityManagerInterface::class)
->getRepository(Entry::class)
->find($entry2->getId());
- $this->assertSame(1, $res->isArchived());
+ $this->assertTrue($res->isArchived());
$crawler = $client->request('GET', '/all/list');
$token = $crawler->filter('#form_mass_action input[name=token]')->attr('value');
diff --git a/tests/Controller/FeedControllerTest.php b/tests/Controller/FeedControllerTest.php
index 0359e8888..a2affdb67 100644
--- a/tests/Controller/FeedControllerTest.php
+++ b/tests/Controller/FeedControllerTest.php
@@ -127,7 +127,7 @@ class FeedControllerTest extends WallabagTestCase
$client = $this->getTestClient();
$client->request('GET', '/feed/admin/SUPERTOKEN/starred');
- $this->assertSame(200, $client->getResponse()->getStatusCode(), 1);
+ $this->assertSame(200, $client->getResponse()->getStatusCode());
$this->validateDom($client->getResponse()->getContent(), 'starred');
}
diff --git a/tests/Mailer/AuthCodeMailerTest.php b/tests/Mailer/AuthCodeMailerTest.php
index b71ba56d6..4b6baaea0 100644
--- a/tests/Mailer/AuthCodeMailerTest.php
+++ b/tests/Mailer/AuthCodeMailerTest.php
@@ -54,7 +54,7 @@ TWIG;
$user = new User();
$user->setEmailTwoFactor(true);
- $user->setEmailAuthCode(666666);
+ $user->setEmailAuthCode('666666');
$user->setEmail('test@wallabag.io');
$user->setName('Bob');