mirror of
https://github.com/wallabag/wallabag.git
synced 2025-06-27 16:36:00 +00:00
PHPStan level 5
This commit is contained in:
parent
3ef7064ada
commit
36eb513e1b
22 changed files with 60 additions and 47 deletions
|
@ -2,7 +2,7 @@ includes:
|
|||
- phpstan-baseline.neon
|
||||
|
||||
parameters:
|
||||
level: 4
|
||||
level: 5
|
||||
paths:
|
||||
- src
|
||||
- tests
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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.');
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -383,7 +383,7 @@ class Entry
|
|||
|
||||
public function toggleArchive()
|
||||
{
|
||||
$this->updateArchived($this->isArchived() ^ 1);
|
||||
$this->updateArchived((bool) ($this->isArchived() ^ 1));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -285,13 +285,13 @@ class EntriesExport
|
|||
'<dt>' . $this->translator->trans('entry.metadata.added_on') . '</dt><dd>' . $entry->getCreatedAt()->format('Y-m-d') . '</dd>' .
|
||||
'<dt>' . $this->translator->trans('entry.metadata.address') . '</dt><dd><a href="' . $entry->getUrl() . '">' . $entry->getUrl() . '</a></dd>' .
|
||||
'</dl>';
|
||||
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
|
||||
$pdf->writeHTMLCell(0, 0, null, null, $html, 0, 1);
|
||||
|
||||
$pdf->AddPage();
|
||||
$html = '<h1>' . $entry->getTitle() . '</h1>';
|
||||
$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);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
@ -173,7 +173,7 @@ class EntryRepository extends ServiceEntityRepository
|
|||
*
|
||||
* @param int $userId
|
||||
* @param string $term
|
||||
* @param string $currentRoute
|
||||
* @param 'starred'|'unread'|'homepage'|'archive'|null $currentRoute
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue