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

Modernize to PHP 8.0

This commit is contained in:
Yassine Guedidi 2025-04-05 13:56:56 +02:00
parent 1d5674a230
commit a107773c11
31 changed files with 97 additions and 199 deletions

View file

@ -120,19 +120,12 @@ class AppKernel extends Kernel
private function processDatabaseParameters(ContainerBuilder $container)
{
switch ($container->getParameter('database_driver')) {
case 'pdo_mysql':
$scheme = 'mysql';
break;
case 'pdo_pgsql':
$scheme = 'pgsql';
break;
case 'pdo_sqlite':
$scheme = 'sqlite';
break;
default:
throw new RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver'));
}
$scheme = match ($container->getParameter('database_driver')) {
'pdo_mysql' => 'mysql',
'pdo_pgsql' => 'pgsql',
'pdo_sqlite' => 'sqlite',
default => throw new RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver')),
};
$container->setParameter('database_scheme', $scheme);

View file

@ -23,5 +23,5 @@ return RectorConfig::configure()
__DIR__ . '/src/Entity/*',
],
])
->withPhpSets(php74: true)
->withPhpSets(php80: true)
->withTypeCoverageLevel(0);

View file

@ -51,7 +51,7 @@ class CleanDuplicatesCommand extends Command
try {
$user = $this->getUser($username);
$this->cleanDuplicates($user);
} catch (NoResultException $e) {
} catch (NoResultException) {
$this->io->error(\sprintf('User "%s" not found.', $username));
return 1;

View file

@ -45,7 +45,7 @@ class GenerateUrlHashesCommand extends Command
try {
$user = $this->getUser($username);
$this->generateHashedUrls($user);
} catch (NoResultException $e) {
} catch (NoResultException) {
$output->writeln(\sprintf('<error>User "%s" not found.</error>', $username));
return 1;

View file

@ -97,43 +97,20 @@ class ImportCommand extends Command
$this->tokenStorage->setToken($token);
$user = $this->tokenStorage->getToken()->getUser();
switch ($input->getOption('importer')) {
case 'v2':
$import = $this->wallabagV2Import;
break;
case 'firefox':
$import = $this->firefoxImport;
break;
case 'chrome':
$import = $this->chromeImport;
break;
case 'readability':
$import = $this->readabilityImport;
break;
case 'instapaper':
$import = $this->instapaperImport;
break;
case 'pinboard':
$import = $this->pinboardImport;
break;
case 'delicious':
$import = $this->deliciousImport;
break;
case 'elcurator':
$import = $this->elcuratorImport;
break;
case 'shaarli':
$import = $this->shaarliImport;
break;
case 'pocket':
$import = $this->pocketHtmlImport;
break;
case 'omnivore':
$import = $this->omnivoreImport;
break;
default:
$import = $this->wallabagV1Import;
}
$import = match ($input->getOption('importer')) {
'v2' => $this->wallabagV2Import,
'firefox' => $this->firefoxImport,
'chrome' => $this->chromeImport,
'readability' => $this->readabilityImport,
'instapaper' => $this->instapaperImport,
'pinboard' => $this->pinboardImport,
'delicious' => $this->deliciousImport,
'elcurator' => $this->elcuratorImport,
'shaarli' => $this->shaarliImport,
'pocket' => $this->pocketHtmlImport,
'omnivore' => $this->omnivoreImport,
default => $this->wallabagV1Import,
};
$import->setMarkAsRead($input->getOption('markAsRead'));
$import->setDisableContentUpdate($input->getOption('disableContentUpdate'));

View file

@ -402,7 +402,7 @@ class InstallCommand extends Command
try {
return \in_array($databaseName, $schemaManager->listDatabases(), true);
} catch (DriverException $e) {
} catch (DriverException) {
// it means we weren't able to get database list, assume the database doesn't exist
return false;

View file

@ -55,7 +55,7 @@ class ReloadEntryCommand extends Command
$userId = $this->userRepository
->findOneByUserName($username)
->getId();
} catch (NoResultException $e) {
} catch (NoResultException) {
$io->error(\sprintf('User "%s" not found.', $username));
return 1;

View file

@ -44,7 +44,7 @@ class ShowUserCommand extends Command
try {
$user = $this->getUser($username);
$this->showUser($user);
} catch (NoResultException $e) {
} catch (NoResultException) {
$this->io->error(\sprintf('User "%s" not found.', $username));
return 1;

View file

@ -43,7 +43,7 @@ class TagAllCommand extends Command
try {
$user = $this->getUser($input->getArgument('username'));
} catch (NoResultException $e) {
} catch (NoResultException) {
$io->error(\sprintf('User "%s" not found.', $input->getArgument('username')));
return 1;

View file

@ -379,7 +379,7 @@ class EntryController extends AbstractController
try {
$entry = $this->entryRepository
->getRandomEntry($this->getUser()->getId(), $type);
} catch (NoResultException $e) {
} catch (NoResultException) {
$this->addFlash('notice', 'flashes.entry.notice.no_random_entry');
return $this->redirect($this->generateUrl($type));
@ -670,7 +670,7 @@ class EntryController extends AbstractController
try {
$entries->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
} catch (OutOfRangeCurrentPageException) {
if ($page > 1) {
return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
}
@ -699,7 +699,7 @@ class EntryController extends AbstractController
try {
$this->contentProxy->updateEntry($entry, $entry->getUrl());
} catch (\Exception $e) {
} catch (\Exception) {
// $this->logger->error('Error while saving an entry', [
// 'exception' => $e,
// 'entry' => $entry,

View file

@ -141,7 +141,7 @@ class FeedController extends AbstractController
try {
$entries->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
} catch (OutOfRangeCurrentPageException) {
if ($page > 1) {
return $this->redirect($url . '?page=' . $entries->getNbPages(), 302);
}
@ -189,22 +189,13 @@ class FeedController extends AbstractController
*/
private function showEntries(string $type, User $user, $page = 1)
{
switch ($type) {
case 'starred':
$qb = $this->entryRepository->getBuilderForStarredByUser($user->getId());
break;
case 'archive':
$qb = $this->entryRepository->getBuilderForArchiveByUser($user->getId());
break;
case 'unread':
$qb = $this->entryRepository->getBuilderForUnreadByUser($user->getId());
break;
case 'all':
$qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
break;
default:
throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));
}
$qb = match ($type) {
'starred' => $this->entryRepository->getBuilderForStarredByUser($user->getId()),
'archive' => $this->entryRepository->getBuilderForArchiveByUser($user->getId()),
'unread' => $this->entryRepository->getBuilderForUnreadByUser($user->getId()),
'all' => $this->entryRepository->getBuilderForAllByUser($user->getId()),
default => throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type)),
};
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
$entries = new Pagerfanta($pagerAdapter);
@ -223,7 +214,7 @@ class FeedController extends AbstractController
try {
$entries->setCurrentPage((int) $page);
} catch (OutOfRangeCurrentPageException $e) {
} catch (OutOfRangeCurrentPageException) {
if ($page > 1) {
return $this->redirect($url . '/' . $entries->getNbPages());
}

View file

@ -62,7 +62,7 @@ class ImportController extends AbstractController
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket_html')
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('omnivore')
;
} catch (\Exception $e) {
} catch (\Exception) {
$rabbitNotInstalled = true;
}
} elseif ($craueConfig->get('import_with_redis')) {
@ -81,7 +81,7 @@ class ImportController extends AbstractController
+ $this->redisClient->llen('wallabag.import.pocket_html')
+ $this->redisClient->llen('wallabag.import.omnivore')
;
} catch (\Exception $e) {
} catch (\Exception) {
$redisNotInstalled = true;
}
}

View file

@ -153,7 +153,7 @@ class TagController extends AbstractController
try {
$entries->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
} catch (OutOfRangeCurrentPageException) {
if ($page > 1) {
return $this->redirect($this->generateUrl($request->attributes->get('_route'), [
'slug' => $tag->getSlug(),

View file

@ -169,7 +169,7 @@ class UserController extends AbstractController
try {
$pagerFanta->setCurrentPage($page);
} catch (OutOfRangeCurrentPageException $e) {
} catch (OutOfRangeCurrentPageException) {
if ($page > 1) {
return $this->redirect($this->generateUrl('user_index', ['page' => $pagerFanta->getNbPages()]), 302);
}

View file

@ -19,7 +19,7 @@ use Wallabag\Repository\TagRepository;
#[ORM\Table(name: '`tag`')]
#[ORM\Index(columns: ['label'])]
#[ORM\Entity(repositoryClass: TagRepository::class)]
class Tag
class Tag implements \Stringable
{
/**
* @var int
@ -54,7 +54,7 @@ class Tag
$this->entries = new ArrayCollection();
}
public function __toString()
public function __toString(): string
{
return $this->label;
}

View file

@ -67,7 +67,7 @@ class AuthenticatorProvider implements ExpressionFunctionProviderInterface
$crawler = new Crawler((string) $html);
$crawler = $crawler->filterXPath($xpathQuery);
} catch (\Throwable $e) {
} catch (\Throwable) {
return '';
}

View file

@ -171,7 +171,7 @@ class DownloadImages
try {
$im = imagecreatefromstring($res->getContent());
} catch (\Exception $e) {
} catch (\Exception) {
$im = false;
}
@ -190,7 +190,7 @@ class DownloadImages
$imagick->readImageBlob($res->getContent());
$imagick->setImageFormat('gif');
$imagick->writeImages($localPath, true);
} catch (\Exception $e) {
} catch (\Exception) {
// if Imagick fail, fallback to the default solution
imagegif($im, $localPath);
}

View file

@ -36,14 +36,9 @@ class AdminVoter extends Voter
return false;
}
switch ($attribute) {
case self::LIST_USERS:
case self::CREATE_USERS:
case self::LIST_IGNORE_ORIGIN_INSTANCE_RULES:
case self::CREATE_IGNORE_ORIGIN_INSTANCE_RULES:
return $this->security->isGranted('ROLE_SUPER_ADMIN');
}
return false;
return match ($attribute) {
self::LIST_USERS, self::CREATE_USERS, self::LIST_IGNORE_ORIGIN_INSTANCE_RULES, self::CREATE_IGNORE_ORIGIN_INSTANCE_RULES => $this->security->isGranted('ROLE_SUPER_ADMIN'),
default => false,
};
}
}

View file

@ -35,12 +35,9 @@ class AnnotationVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getUser() === $user,
default => false,
};
}
}

View file

@ -47,24 +47,9 @@ class EntryVoter extends Voter
return false;
}
switch ($attribute) {
case self::VIEW:
case self::EDIT:
case self::RELOAD:
case self::STAR:
case self::ARCHIVE:
case self::SHARE:
case self::UNSHARE:
case self::EXPORT:
case self::DELETE:
case self::LIST_ANNOTATIONS:
case self::CREATE_ANNOTATIONS:
case self::LIST_TAGS:
case self::TAG:
case self::UNTAG:
return $user === $subject->getUser();
}
return false;
return match ($attribute) {
self::VIEW, self::EDIT, self::RELOAD, self::STAR, self::ARCHIVE, self::SHARE, self::UNSHARE, self::EXPORT, self::DELETE, self::LIST_ANNOTATIONS, self::CREATE_ANNOTATIONS, self::LIST_TAGS, self::TAG, self::UNTAG => $user === $subject->getUser(),
default => false,
};
}
}

View file

@ -32,12 +32,9 @@ class IgnoreOriginInstanceRuleVoter extends Voter
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $this->security->isGranted('ROLE_SUPER_ADMIN');
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $this->security->isGranted('ROLE_SUPER_ADMIN'),
default => false,
};
}
}

View file

@ -35,12 +35,9 @@ class IgnoreOriginUserRuleVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getConfig()->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getConfig()->getUser() === $user,
default => false,
};
}
}

View file

@ -41,22 +41,9 @@ class MainVoter extends Voter
protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
{
switch ($attribute) {
case self::LIST_ENTRIES:
case self::CREATE_ENTRIES:
case self::EDIT_ENTRIES:
case self::EXPORT_ENTRIES:
case self::IMPORT_ENTRIES:
case self::DELETE_ENTRIES:
case self::LIST_TAGS:
case self::CREATE_TAGS:
case self::DELETE_TAGS:
case self::LIST_SITE_CREDENTIALS:
case self::CREATE_SITE_CREDENTIALS:
case self::EDIT_CONFIG:
return $this->security->isGranted('ROLE_USER');
}
return false;
return match ($attribute) {
self::LIST_ENTRIES, self::CREATE_ENTRIES, self::EDIT_ENTRIES, self::EXPORT_ENTRIES, self::IMPORT_ENTRIES, self::DELETE_ENTRIES, self::LIST_TAGS, self::CREATE_TAGS, self::DELETE_TAGS, self::LIST_SITE_CREDENTIALS, self::CREATE_SITE_CREDENTIALS, self::EDIT_CONFIG => $this->security->isGranted('ROLE_USER'),
default => false,
};
}
}

View file

@ -35,12 +35,9 @@ class SiteCredentialVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $user === $subject->getUser();
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $user === $subject->getUser(),
default => false,
};
}
}

View file

@ -42,13 +42,9 @@ class TagVoter extends Voter
return false;
}
switch ($attribute) {
case self::VIEW:
case self::EDIT:
case self::DELETE:
return $this->security->isGranted('ROLE_USER');
}
return false;
return match ($attribute) {
self::VIEW, self::EDIT, self::DELETE => $this->security->isGranted('ROLE_USER'),
default => false,
};
}
}

View file

@ -35,12 +35,9 @@ class TaggingRuleVoter extends Voter
return false;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
return $subject->getConfig()->getUser() === $user;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE => $subject->getConfig()->getUser() === $user,
default => false,
};
}
}

View file

@ -21,7 +21,7 @@ class ArraySiteConfigBuilder implements SiteConfigBuilder
{
$host = strtolower($host);
if ('www.' === substr($host, 0, 4)) {
if (str_starts_with($host, 'www.')) {
$host = substr($host, 4);
}

View file

@ -26,7 +26,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
// required by credentials below
$host = strtolower($host);
if ('www.' === substr($host, 0, 4)) {
if (str_starts_with($host, 'www.')) {
$host = substr($host, 4);
}

View file

@ -66,7 +66,7 @@ class LoginFormAuthenticator
$crawler = new Crawler((string) $html);
$loggedIn = $crawler->evaluate((string) $siteConfig->getNotLoggedInXpath());
} catch (\Throwable $e) {
} catch (\Throwable) {
return false;
}
@ -98,7 +98,7 @@ class LoginFormAuthenticator
$extraFields = [];
foreach ($siteConfig->getExtraFields() as $fieldName => $fieldValue) {
if ('@=' === substr($fieldValue, 0, 2)) {
if (str_starts_with($fieldValue, '@=')) {
$fieldValue = $this->expressionLanguage->evaluate(
substr($fieldValue, 2),
[

View file

@ -89,25 +89,14 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface
return 0;
}
switch ($type) {
case 'starred':
$qb = $this->entryRepository->getCountBuilderForStarredByUser($user->getId())->select('COUNT(e.id)');
break;
case 'archive':
$qb = $this->entryRepository->getCountBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)');
break;
case 'unread':
$qb = $this->entryRepository->getCountBuilderForUnreadByUser($user->getId())->select('COUNT(e.id)');
break;
case 'annotated':
$qb = $this->annotationRepository->getCountBuilderByUser($user->getId())->select('COUNT(DISTINCT e.entry)');
break;
case 'all':
$qb = $this->entryRepository->getCountBuilderForAllByUser($user->getId())->select('COUNT(e.id)');
break;
default:
throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type));
}
$qb = match ($type) {
'starred' => $this->entryRepository->getCountBuilderForStarredByUser($user->getId())->select('COUNT(e.id)'),
'archive' => $this->entryRepository->getCountBuilderForArchiveByUser($user->getId())->select('COUNT(e.id)'),
'unread' => $this->entryRepository->getCountBuilderForUnreadByUser($user->getId())->select('COUNT(e.id)'),
'annotated' => $this->annotationRepository->getCountBuilderByUser($user->getId())->select('COUNT(DISTINCT e.entry)'),
'all' => $this->entryRepository->getCountBuilderForAllByUser($user->getId())->select('COUNT(e.id)'),
default => throw new \InvalidArgumentException(\sprintf('Type "%s" is not implemented.', $type)),
};
$query = $qb->getQuery();
$query->useQueryCache(true);

View file

@ -120,7 +120,7 @@ abstract class WallabagTestCase extends WebTestCase
{
try {
$this->client->getContainer()->get(Client::class)->connect();
} catch (\Exception $e) {
} catch (\Exception) {
$this->markTestSkipped('Redis is not installed/activated');
}
}