From 7b28486b9cee5f0c59c7749f0977f335c2d061b7 Mon Sep 17 00:00:00 2001 From: Nicolas Roudaire Date: Tue, 9 Nov 2021 20:45:52 +0100 Subject: [PATCH] Upgrade PHPStan to major release 1. Need code refactoring : cope with #81 --- .github/workflows/phyxo.yml | 2 +- composer.json | 4 +- composer.lock | 267 +++++++++--------- .../Admin/AdminHistoryController.php | 60 +++- src/Controller/PictureController.php | 38 ++- src/Controller/SearchController.php | 44 ++- src/DataMapper/AlbumMapper.php | 31 +- src/Entity/User.php | 1 + src/EventSubscriber/LocaleSubscriber.php | 5 +- src/EventSubscriber/TablePrefixSubscriber.php | 1 + src/Notification.php | 24 +- src/Phyxo/Conf.php | 3 +- src/Phyxo/Functions/Ws/Extension.php | 8 +- src/Phyxo/Functions/Ws/Image.php | 11 +- src/Phyxo/Functions/Ws/Main.php | 7 +- src/Phyxo/Functions/Ws/Permission.php | 8 +- src/Phyxo/Image/DerivativeImage.php | 7 +- src/Phyxo/Plugin/Plugins.php | 4 +- src/Phyxo/TabSheet/TabSheet.php | 3 +- src/Phyxo/Theme/DummyThemeMaintain.php | 1 + src/Phyxo/Theme/Themes.php | 2 +- src/Security/LoginFormAuthenticator.php | 5 +- 22 files changed, 320 insertions(+), 216 deletions(-) diff --git a/.github/workflows/phyxo.yml b/.github/workflows/phyxo.yml index d29d3cbe9..ec5c68ced 100644 --- a/.github/workflows/phyxo.yml +++ b/.github/workflows/phyxo.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - php-versions: [7.3, 7.4, 8.0] + php-versions: [7.4, 8.0] # experimental: [false] mysql: [5.7] # include: diff --git a/composer.json b/composer.json index ca10a36e2..9b014f8a4 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,8 @@ "friendsofphp/php-cs-fixer": "^3.2", "openpsa/universalfeedcreator": "^1.8", "pclzip/pclzip": "^2.8", + "phpstan/phpstan": "^1.1", + "phpstan/phpstan-doctrine": "^1.0", "ramsey/uuid-doctrine": "^1.6", "symfony/asset": "4.4.*", "symfony/console": "4.4.*", @@ -44,8 +46,6 @@ "dmore/behat-chrome-extension": "^1.3", "phpspec/prophecy": "^1.11", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12.42", - "phpstan/phpstan-doctrine": "^0.12.19", "symfony/browser-kit": "^4.4", "symfony/css-selector": "^4.4", "symfony/maker-bundle": "^1.21", diff --git a/composer.lock b/composer.lock index 3dc8ffa6d..a94da075f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9e311ceaf3199da46061b27fb58006f1", + "content-hash": "2354d43e560b1f7ee6497ff48f2875a3", "packages": [ { "name": "brick/math", @@ -1848,6 +1848,139 @@ }, "time": "2020-10-14T08:32:19+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "bcea0ae85868a89d5789c75f012c93129f842934" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bcea0ae85868a89d5789c75f012c93129f842934", + "reference": "bcea0ae85868a89d5789c75f012c93129f842934", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.1.2" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-11-09T12:41:09+00:00" + }, + { + "name": "phpstan/phpstan-doctrine", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-doctrine.git", + "reference": "ea3919219c4915f4a3896227aaa9e5d3d2034bd7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/ea3919219c4915f4a3896227aaa9e5d3d2034bd7", + "reference": "ea3919219c4915f4a3896227aaa9e5d3d2034bd7", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "phpstan/phpstan": "^1.0" + }, + "conflict": { + "doctrine/collections": "<1.0", + "doctrine/common": "<2.7", + "doctrine/mongodb-odm": "<1.2", + "doctrine/orm": "<2.5", + "doctrine/persistence": "<1.3" + }, + "require-dev": { + "doctrine/annotations": "^1.11.0", + "doctrine/collections": "^1.6", + "doctrine/common": "^2.7 || ^3.0", + "doctrine/dbal": "^2.13.1", + "doctrine/mongodb-odm": "^1.3 || ^2.1", + "doctrine/orm": "^2.9.1", + "doctrine/persistence": "^1.1 || ^2.0", + "nesbot/carbon": "^2.49", + "nikic/php-parser": "^4.13.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "ramsey/uuid-doctrine": "^1.5.0" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + }, + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Doctrine extensions for PHPStan", + "support": { + "issues": "https://github.com/phpstan/phpstan-doctrine/issues", + "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.0.1" + }, + "time": "2021-11-02T13:28:55+00:00" + }, { "name": "psr/cache", "version": "1.0.1", @@ -8349,138 +8482,6 @@ }, "time": "2020-12-13T13:06:13+00:00" }, - { - "name": "phpstan/phpstan", - "version": "0.12.99", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7", - "shasum": "" - }, - "require": { - "php": "^7.1|^8.0" - }, - "conflict": { - "phpstan/phpstan-shim": "*" - }, - "bin": [ - "phpstan", - "phpstan.phar" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan - PHP Static Analysis Tool", - "support": { - "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.99" - }, - "funding": [ - { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://github.com/phpstan", - "type": "github" - }, - { - "url": "https://www.patreon.com/phpstan", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" - } - ], - "time": "2021-09-12T20:09:55+00:00" - }, - { - "name": "phpstan/phpstan-doctrine", - "version": "0.12.44", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/5fe9a9b15707d9bc5178fa7cf0899e904d112ccd", - "reference": "5fe9a9b15707d9bc5178fa7cf0899e904d112ccd", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^0.12.85" - }, - "conflict": { - "doctrine/collections": "<1.0", - "doctrine/common": "<2.7", - "doctrine/mongodb-odm": "<1.2", - "doctrine/orm": "<2.5", - "doctrine/persistence": "<1.3" - }, - "require-dev": { - "doctrine/annotations": "^1.11.0", - "doctrine/collections": "^1.6", - "doctrine/common": "^2.7 || ^3.0", - "doctrine/dbal": "^2.13.1", - "doctrine/mongodb-odm": "^1.3 || ^2.1", - "doctrine/orm": "^2.9.1", - "doctrine/persistence": "^1.1 || ^2.0", - "nesbot/carbon": "^2.49", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^0.12.16", - "phpstan/phpstan-strict-rules": "^0.12.5", - "phpunit/phpunit": "^9.5", - "ramsey/uuid-doctrine": "^1.5.0" - }, - "type": "phpstan-extension", - "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - }, - "phpstan": { - "includes": [ - "extension.neon", - "rules.neon" - ] - } - }, - "autoload": { - "psr-4": { - "PHPStan\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Doctrine extensions for PHPStan", - "support": { - "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/0.12.44" - }, - "time": "2021-09-01T06:46:16+00:00" - }, { "name": "sebastian/comparator", "version": "4.0.6", diff --git a/src/Controller/Admin/AdminHistoryController.php b/src/Controller/Admin/AdminHistoryController.php index 849be0b4c..2a74fca8f 100644 --- a/src/Controller/Admin/AdminHistoryController.php +++ b/src/Controller/Admin/AdminHistoryController.php @@ -63,9 +63,15 @@ protected function setTabsheet(string $section = 'stats'): array return ['tabsheet' => $tabsheet]; } - public function stats(Request $request, int $year = null, int $month = null, int $day = null, Conf $conf, HistorySummaryRepository $historySummaryRepository, - HistoryRepository $historyRepository) - { + public function stats( + Request $request, + int $year = null, + int $month = null, + int $day = null, + Conf $conf, + HistorySummaryRepository $historySummaryRepository, + HistoryRepository $historyRepository + ) { $tpl_params = []; $_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath(); @@ -186,10 +192,19 @@ public function stats(Request $request, int $year = null, int $month = null, int return $this->render('history_stats.html.twig', $tpl_params); } - public function search(Request $request, SearchRepository $searchRepository, int $start, int $search_id = null, AlbumMapper $albumMapper, Conf $conf, - UserRepository $userRepository, UserMapper $userMapper, ImageMapper $imageMapper, - TagRepository $tagRepository, HistoryRepository $historyRepository) - { + public function search( + Request $request, + SearchRepository $searchRepository, + int $start, + int $search_id = null, + AlbumMapper $albumMapper, + Conf $conf, + UserRepository $userRepository, + UserMapper $userMapper, + ImageMapper $imageMapper, + TagRepository $tagRepository, + HistoryRepository $historyRepository + ) { $tpl_params = []; $_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath(); @@ -205,8 +220,15 @@ public function search(Request $request, SearchRepository $searchRepository, int } $tpl_params['search_results'] = $this->getElementFromSearchRules( - $rules, $start, $conf, $historyRepository, - $albumMapper, $userMapper, $imageMapper, $userRepository, $tagRepository + $rules, + $start, + $conf, + $historyRepository, + $albumMapper, + $userMapper, + $imageMapper, + $userRepository, + $tagRepository ); $tpl_params['search_summary'] = $tpl_params['search_results']['search_summary']; $nb_lines = $tpl_params['search_results']['nb_lines']; @@ -218,7 +240,7 @@ public function search(Request $request, SearchRepository $searchRepository, int $nb_lines, $start, $conf['nb_logs_page'] - ); + ); } $tpl_params['display_thumbnail_selected'] = $request->request->get('display_thumbnail') ?? ''; @@ -247,9 +269,17 @@ public function search(Request $request, SearchRepository $searchRepository, int return $this->render('history_search.html.twig', $tpl_params); } - protected function getElementFromSearchRules(array $rules, int $start, Conf $conf, HistoryRepository $historyRepository, AlbumMapper $albumMapper, UserMapper $userMapper, - ImageMapper $imageMapper, UserRepository $userRepository, TagRepository $tagRepository): array - { + protected function getElementFromSearchRules( + array $rules, + int $start, + Conf $conf, + HistoryRepository $historyRepository, + AlbumMapper $albumMapper, + UserMapper $userMapper, + ImageMapper $imageMapper, + UserRepository $userRepository, + TagRepository $tagRepository + ): array { $search_results = []; if (isset($rules['fields']['filename'])) { @@ -540,12 +570,14 @@ public function saveSearch(Request $request, SearchRepository $searchRepository) setcookie('display_thumbnail', $cookie_val, strtotime('+1 month'), $request->getBasePath()); // TODO manage inconsistency of having $_POST['image_id'] and $_POST['filename'] simultaneously - if (!empty($rules)) { + /** @phpstan-ignore-next-line */ + if (count($rules) > 0) { $search = new Search(); $search->setRules(base64_encode(serialize($rules))); $searchRepository->addSearch($search); return $this->redirectToRoute('admin_history_search', ['search_id' => $search->getId()]); + /** @phpstan-ignore-next-line */ } else { $this->addFlash('error', $this->translator->trans('Empty query. No criteria has been entered.', [], 'admin')); return $this->redirectToRoute('admin_history_search'); diff --git a/src/Controller/PictureController.php b/src/Controller/PictureController.php index 3c260633d..c0e1c7eb5 100644 --- a/src/Controller/PictureController.php +++ b/src/Controller/PictureController.php @@ -42,12 +42,27 @@ class PictureController extends CommonController private $userMapper, $translator; private const VALID_COMMENT = 'valid_comment'; - public function picture(Request $request, int $image_id, string $type, string $element_id, Conf $conf, AlbumMapper $albumMapper, - MenuBar $menuBar, ImageStandardParams $image_std_params, TagMapper $tagMapper, - UserMapper $userMapper, CommentMapper $commentMapper, CsrfTokenManagerInterface $csrfTokenManager, - ImageMapper $imageMapper, Metadata $metadata, TranslatorInterface $translator, RateRepository $rateRepository, - FavoriteRepository $favoriteRepository, ImageAlbumRepository $imageAlbumRepository, EventDispatcherInterface $eventDispatcher) - { + public function picture( + Request $request, + int $image_id, + string $type, + string $element_id, + Conf $conf, + AlbumMapper $albumMapper, + MenuBar $menuBar, + ImageStandardParams $image_std_params, + TagMapper $tagMapper, + UserMapper $userMapper, + CommentMapper $commentMapper, + CsrfTokenManagerInterface $csrfTokenManager, + ImageMapper $imageMapper, + Metadata $metadata, + TranslatorInterface $translator, + RateRepository $rateRepository, + FavoriteRepository $favoriteRepository, + ImageAlbumRepository $imageAlbumRepository, + EventDispatcherInterface $eventDispatcher + ) { $_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath(); $this->translator = $translator; $tpl_params = []; @@ -106,7 +121,7 @@ public function picture(Request $request, int $image_id, string $type, string $e if ($conf['picture_download_icon']) { if ($picture['src_image']->is_original()) { // we have a photo - if (!empty(['enabled_high'])) { + if ($this->getUser()->getUserInfos()->hasEnabledHigh()) { $picture['element_url'] = $picture['src_image']->getUrl(); $picture['U_DOWNLOAD'] = $this->generateUrl('action', ['image_id' => $image_id, 'part' => 'e', 'download' => 'download']); } @@ -190,20 +205,23 @@ public function picture(Request $request, int $image_id, string $type, string $e 'url' => $this->generateUrl('calendar_categories_monthly', ['date_type' => 'created', 'view_type' => 'calendar']) ]; + /** @phpstan-ignore-next-line */ if (!empty($picture['author'])) { $tpl_params['INFO_AUTHOR'] = $picture['author']; } + /** @phpstan-ignore-next-line */ if (!empty($picture['comment'])) { $tpl_params['COMMENT_IMG'] = $picture['comment']; } - $tpl_params['INFO_VISITS'] = $picture['hit']; $tpl_params['INFO_FILE'] = $picture['file']; + /** @phpstan-ignore-next-line */ if (!empty($picture['filesize'])) { $tpl_params['INFO_FILESIZE'] = $translator->trans('{size} Kb', ['size' => $picture['filesize']]); } + /** @phpstan-ignore-next-line */ if ($picture['src_image']->is_original() && isset($picture['width'])) { $tpl_params['INFO_DIMENSIONS'] = $picture['width'] . '*' . $picture['height']; } @@ -240,7 +258,7 @@ public function picture(Request $request, int $image_id, string $type, string $e 'URL' => $this->generateUrl('images_by_tags', ['tag_ids' => $tag->toUrl()]), 'U_TAG_IMAGE' => $this->generateUrl('images_by_tags', ['tag_ids' => $tag->toUrl()]), ] - ); + ); } } @@ -438,7 +456,7 @@ public function picture(Request $request, int $image_id, string $type, string $e 'KEY' => $csrfTokenManager->getToken(self::VALID_COMMENT), ]; - if (!empty($comment_action) && $comment_action === 'reject') { + if (!is_null($comment_action) && $comment_action === 'reject') { foreach (['content', 'author', 'website_url', 'email'] as $k) { $tpl_var[strtoupper($k)] = htmlspecialchars(stripslashes($request->request->get($k))); } diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 867d11557..42496e22d 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -60,9 +60,16 @@ public function qsearch(Request $request, Conf $conf, MenuBar $menuBar, SearchRe return $this->redirectToRoute('search_results', ['search_id' => $search_id]); } - public function search(Request $request, TagMapper $tagMapper, AlbumMapper $albumMapper, Conf $conf, - SearchRepository $searchRepository, MenuBar $menuBar, TranslatorInterface $translator, ImageMapper $imageMapper) - { + public function search( + Request $request, + TagMapper $tagMapper, + AlbumMapper $albumMapper, + Conf $conf, + SearchRepository $searchRepository, + MenuBar $menuBar, + TranslatorInterface $translator, + ImageMapper $imageMapper + ) { $tpl_params = []; $_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath(); @@ -153,6 +160,7 @@ public function search(Request $request, TagMapper $tagMapper, AlbumMapper $albu ]; } + /** @phpstan-ignore-next-line */ if ($request->request->get('authors') && is_array($request->request->get('authors')) && count($request->request->get('authors')) > 0) { $authors = []; @@ -246,8 +254,18 @@ public function search(Request $request, TagMapper $tagMapper, AlbumMapper $albu return $this->render('search.html.twig', $tpl_params); } - public function searchResults(Request $request, SearchMapper $searchMapper, AlbumMapper $albumMapper, ImageMapper $imageMapper, Conf $conf, - SearchRepository $searchRepository, ImageStandardParams $image_std_params, MenuBar $menuBar, $search_id, TranslatorInterface $translator, int $start = 0 + public function searchResults( + Request $request, + SearchMapper $searchMapper, + AlbumMapper $albumMapper, + ImageMapper $imageMapper, + Conf $conf, + SearchRepository $searchRepository, + ImageStandardParams $image_std_params, + MenuBar $menuBar, + $search_id, + TranslatorInterface $translator, + int $start = 0 ) { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -272,6 +290,7 @@ public function searchResults(Request $request, SearchMapper $searchMapper, Albu $tpl_params['items'] = $searchMapper->getSearchResults($rules, $this->getUser()); } + /** @phpstan-ignore-next-line */ if (!empty($search_results['qsearch_details'])) { $cats = []; if (!empty($search_results['qsearch_details']['matching_cats_no_image'])) { @@ -321,10 +340,12 @@ public function searchResults(Request $request, SearchMapper $searchMapper, Albu ) ); + /** @phpstan-ignore-next-line */ if (!empty($search_results['qsearch_details']) && !empty($search_results['qsearch_details']['unmatched_terms'])) { $tpl_params['no_search_results'] = $search_results['qsearch_details']['unmatched_terms']; } } else { + /** @phpstan-ignore-next-line */ if (!empty($search_results['qsearch_details']) && !empty($search_results['qsearch_details']['q'])) { $tpl_params['no_search_results'] = $search_results['qsearch_details']['q']; } @@ -340,9 +361,16 @@ public function searchResults(Request $request, SearchMapper $searchMapper, Albu return $this->render('thumbnails.html.twig', $tpl_params); } - public function searchRules(Request $request, AlbumMapper $albumMapper, Conf $conf, TagRepository $tagRepository, - SearchRepository $searchRepository, int $search_id, MenuBar $menuBar, TranslatorInterface $translator) - { + public function searchRules( + Request $request, + AlbumMapper $albumMapper, + Conf $conf, + TagRepository $tagRepository, + SearchRepository $searchRepository, + int $search_id, + MenuBar $menuBar, + TranslatorInterface $translator + ) { $tpl_params = []; $_SERVER['PUBLIC_BASE_PATH'] = $request->getBasePath(); diff --git a/src/DataMapper/AlbumMapper.php b/src/DataMapper/AlbumMapper.php index efff6a5d1..68d5f8dbb 100644 --- a/src/DataMapper/AlbumMapper.php +++ b/src/DataMapper/AlbumMapper.php @@ -29,9 +29,16 @@ class AlbumMapper { private $conf, $albumRepository, $router, $cache = [], $albums_retrieved = false, $translator, $userRepository, $userCacheAlbumRepository, $imageAlbumRepository, $imageRepository; - public function __construct(Conf $conf, AlbumRepository $albumRepository, RouterInterface $router, TranslatorInterface $translator, UserRepository $userRepository, - UserCacheAlbumRepository $userCacheAlbumRepository, ImageAlbumRepository $imageAlbumRepository, ImageRepository $imageRepository) - { + public function __construct( + Conf $conf, + AlbumRepository $albumRepository, + RouterInterface $router, + TranslatorInterface $translator, + UserRepository $userRepository, + UserCacheAlbumRepository $userCacheAlbumRepository, + ImageAlbumRepository $imageAlbumRepository, + ImageRepository $imageRepository + ) { $this->conf = $conf; $this->albumRepository = $albumRepository; $this->router = $router; @@ -93,9 +100,13 @@ protected function getAlbumsMenu(User $user, array $selected_category = []): arr $album->toArray(), [ 'NAME' => $album->getName(), - 'TITLE' => $this->getDisplayImagesCount($album->getUserCacheAlbums()->first()->getNbImages(), $album->getUserCacheAlbums()->first()->getCountImages(), - $album->getUserCacheAlbums()->first()->getCountAlbums(), false, ' / ' - ), + 'TITLE' => $this->getDisplayImagesCount( + $album->getUserCacheAlbums()->first()->getNbImages(), + $album->getUserCacheAlbums()->first()->getCountImages(), + $album->getUserCacheAlbums()->first()->getCountAlbums(), + false, + ' / ' + ), 'URL' => $this->router->generate('album', ['category_id' => $album->getId()]), 'LEVEL' => substr_count($album->getGlobalRank(), '.') + 1, 'SELECTED' => isset($selected_category['id']) && $selected_category['id'] === $album->getId() ? true : false, @@ -104,9 +115,9 @@ protected function getAlbumsMenu(User $user, array $selected_category = []): arr 'icon_ts' => '' ] ); - if ($this->conf['index_new_icon'] && !empty($row['max_date_last'])) { // @FIX : cf BUGS - // $row['icon_ts'] = $this->em->getRepository(BaseRepository::class)->getIcon($row['max_date_last'], $user, $child_date_last); - } + // if ($this->conf['index_new_icon'] && !empty($row['max_date_last'])) { // @FIX : cf BUGS + // $row['icon_ts'] = $this->em->getRepository(BaseRepository::class)->getIcon($row['max_date_last'], $user, $child_date_last); + // } $albums[$album->getId()] = $album_infos; } uasort($albums, '\Phyxo\Functions\Utils::global_rank_compare'); @@ -279,7 +290,7 @@ public function getAlbumsDisplayNameCache(string $uppercats, string $url = '', b $all_albums = explode(',', $uppercats); $output = ''; if ($single_link) { - $single_url = $this->router->generate('album', ['category_id' => $all_albums[count($all_albums) - 1] ]); + $single_url = $this->router->generate('album', ['category_id' => $all_albums[count($all_albums) - 1]]); $output .= ' 'ROLE_USER' ]; + /** @phpstan-ignore-next-line */ private $salt; /** diff --git a/src/EventSubscriber/LocaleSubscriber.php b/src/EventSubscriber/LocaleSubscriber.php index 1005c6956..5ba182f0b 100644 --- a/src/EventSubscriber/LocaleSubscriber.php +++ b/src/EventSubscriber/LocaleSubscriber.php @@ -18,12 +18,11 @@ class LocaleSubscriber implements EventSubscriberInterface { - private $defaultLocale, $translator; + private $defaultLocale; - public function __construct(string $defaultLanguage, TranslatorInterface $translator) + public function __construct(string $defaultLanguage) { $this->defaultLocale = $defaultLanguage; - $this->translator = $translator; } public function onKernelRequest(RequestEvent $event) diff --git a/src/EventSubscriber/TablePrefixSubscriber.php b/src/EventSubscriber/TablePrefixSubscriber.php index 8c5eff246..a6fd25b91 100644 --- a/src/EventSubscriber/TablePrefixSubscriber.php +++ b/src/EventSubscriber/TablePrefixSubscriber.php @@ -44,6 +44,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event) $classMetadata->setSequenceGeneratorDefinition($newDefinition); $em = $event->getEntityManager(); + /** @phpstan-ignore-next-line */ if (isset($classMetadata->idGenerator)) { $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator( $em->getConfiguration()->getQuoteStrategy()->getSequenceName( diff --git a/src/Notification.php b/src/Notification.php index 06c216787..62db02cad 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -37,10 +37,18 @@ class Notification private $infos = [], $errors = []; - public function __construct(Conf $conf, UserMapper $userMapper, AlbumMapper $albumMapper, RouterInterface $router, ImageMapper $imageMapper, - MailerInterface $mailer, TranslatorInterface $translator, CommentRepository $commentRepository, - UserMailNotificationRepository $userMailNotificationRepository, UserInfosRepository $userInfosRepository) - { + public function __construct( + Conf $conf, + UserMapper $userMapper, + AlbumMapper $albumMapper, + RouterInterface $router, + ImageMapper $imageMapper, + MailerInterface $mailer, + TranslatorInterface $translator, + CommentRepository $commentRepository, + UserMailNotificationRepository $userMailNotificationRepository, + UserInfosRepository $userInfosRepository + ) { $this->conf = $conf; $this->userMapper = $userMapper; $this->albumMapper = $albumMapper; @@ -58,6 +66,7 @@ public function __construct(Conf $conf, UserMapper $userMapper, AlbumMapper $alb 'is_sendmail_timeout' => false ]; + /** @phpstan-ignore-next-line */ if ((!isset($this->env['sendmail_timeout'])) || (!is_numeric($this->env['sendmail_timeout'])) || ($this->env['sendmail_timeout'] <= 0)) { $this->env['sendmail_timeout'] = $conf['nbm_treatment_timeout_default']; } @@ -213,7 +222,8 @@ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = $news, $this->nb_unvalidated_comments($start, $end), 'number_of_new_comments_to_validate', - $this->router->generate('admin_comments', [], UrlGeneratorInterface::ABSOLUTE_URL), $add_url + $this->router->generate('admin_comments', [], UrlGeneratorInterface::ABSOLUTE_URL), + $add_url ); $this->add_news_line( @@ -748,8 +758,8 @@ public function do_action_send_mail_notification($action = 'list_to_send', $chec if ($this->conf['nbm_send_html_mail'] && $this->conf['nbm_send_recent_post_dates']) { $recent_post_dates = $this->get_recent_post_dates_array( - $this->conf['recent_post_dates']['NBM'] - ); + $this->conf['recent_post_dates']['NBM'] + ); foreach ($recent_post_dates as $date_detail) { $tpl_params['recent_posts'][] = [ 'TITLE' => $this->get_title_recent_post_date($date_detail), diff --git a/src/Phyxo/Conf.php b/src/Phyxo/Conf.php index 04518c257..e424325a3 100644 --- a/src/Phyxo/Conf.php +++ b/src/Phyxo/Conf.php @@ -53,7 +53,8 @@ public function loadFromFile($conf_file): void require $conf_file; ob_end_clean(); - if (!empty($conf)) { + /** @phpstan-ignore-next-line */ + if (count($conf) > 0) { foreach ($conf as $key => $value) { $this->keys[self::FILE_PREFIX . $key] = ['value' => $value, 'type' => null]; } diff --git a/src/Phyxo/Functions/Ws/Extension.php b/src/Phyxo/Functions/Ws/Extension.php index d940e3cbb..0bc5bd667 100644 --- a/src/Phyxo/Functions/Ws/Extension.php +++ b/src/Phyxo/Functions/Ws/Extension.php @@ -172,14 +172,10 @@ public static function checkupdates($params, Server $service) if (!$update->isExtensionsNeedUpdate()) { $service->getConf()->addOrUpdateParam('updates_ignored', $update->checkExtensions($updates_ignored)); - } else { - $service->getConf()->addOrUpdateParam('updates_ignored', $update->checkUpdatedExtensions($updates_ignored)); - } - - if (!$update->isExtensionsNeedUpdate()) { $result['ext_need_update'] = false; } else { - $result['ext_need_update'] = !$update->isExtensionsNeedUpdate(); + $service->getConf()->addOrUpdateParam('updates_ignored', $update->checkUpdatedExtensions($updates_ignored)); + $result['ext_need_update'] = true; } return $result; diff --git a/src/Phyxo/Functions/Ws/Image.php b/src/Phyxo/Functions/Ws/Image.php index e78d4ce74..cb3125d14 100644 --- a/src/Phyxo/Functions/Ws/Image.php +++ b/src/Phyxo/Functions/Ws/Image.php @@ -142,7 +142,10 @@ public static function getInfo($params, Server $service) $nb_comments = $service->getManagerRegistry()->getRepository(Comment::class)->countForImage($image->getId(), $service->getUserMapper()->isAdmin()); if ($nb_comments > 0 && $params['comments_per_page'] > 0) { foreach ($service->getManagerRegistry()->getRepository(Comment::class)->getCommentsForImagePerPage( - $image->getId(), $params['comments_per_page'], $params['comments_per_page'] * $params['comments_page']) as $comment) { + $image->getId(), + $params['comments_per_page'], + $params['comments_per_page'] * $params['comments_page'] + ) as $comment) { $related_comments[] = [ 'id' => $comment->getId(), 'content' => $comment->getContent(), @@ -156,6 +159,7 @@ public static function getInfo($params, Server $service) } $comment_post_data = null; + /** @phpstan-ignore-next-line */ if ($is_commentable && (!$service->getUserMapper()->isGuest() || ($service->getUserMapper()->isGuest() && $service->getConf()['comments_forall']))) { $comment_post_data['author'] = $service->getUserMapper()->getUser()->getUsername(); } @@ -779,6 +783,7 @@ public static function exist($params, Server $service) foreach ($filenames as $filename) { $res[$filename] = null; + /** @phpstan-ignore-next-line */ if (isset($id_of_filename[$filename])) { $res[$filename] = $id_of_filename[$filename]; } @@ -860,12 +865,12 @@ public static function setRelatedTags($params, Server $service) $new_tags = array_diff($params['tags'], $current_tags); if (count($removed_tags) > 0) { - if (!$service->getSecurity()->isGranted(TagVoter::DELETE, $image)) { + if ($service->getSecurity()->isGranted(TagVoter::DELETE, $image) == false) { return new Error(403, 'You are not allowed to delete tags'); } } if (count($new_tags) > 0) { - if (!$service->getSecurity()->isGranted(TagVoter::ADD, $image)) { + if ($service->getSecurity()->isGranted(TagVoter::ADD, $image) == false) { return new Error(403, 'You are not allowed to add tags'); } } diff --git a/src/Phyxo/Functions/Ws/Main.php b/src/Phyxo/Functions/Ws/Main.php index 298497711..ecf4750c8 100644 --- a/src/Phyxo/Functions/Ws/Main.php +++ b/src/Phyxo/Functions/Ws/Main.php @@ -81,9 +81,9 @@ public static function getMissingDerivatives($params, Server $service) if ($type != $derivative->get_type()) { continue; } - if (@filemtime($derivative->get_path()) === false) { - $urls[] = $derivative->getUrl() . $uid; - } + // if (@filemtime($derivative->get_path()) === false) { + // $urls[] = $derivative->getUrl() . $uid; + // } } if (count($urls) >= $max_urls) { @@ -215,6 +215,7 @@ public static function stdGetUrls(array $image_row, Server $service) $derivatives_arr = []; foreach ($derivatives as $type => $derivative) { $size = $derivative->get_size(); + /** @phpstan-ignore-next-line */ $size != null or $size = [null, null]; $derivatives_arr[$type] = ['url' => $derivative->getUrl(), 'width' => $size[0], 'height' => $size[1]]; } diff --git a/src/Phyxo/Functions/Ws/Permission.php b/src/Phyxo/Functions/Ws/Permission.php index 4d995309c..0885caa24 100644 --- a/src/Phyxo/Functions/Ws/Permission.php +++ b/src/Phyxo/Functions/Ws/Permission.php @@ -83,21 +83,27 @@ public static function getList($params, Server $service) // filter by group and user foreach ($permissions as $album_id => &$album) { if (!empty($params['group_id'])) { + /** @phpstan-ignore-next-line */ if (empty($album['groups']) || count(array_intersect($album['groups'], $params['group_id'])) === 0) { unset($permissions[$album_id]); continue; } } if (!empty($params['user_id'])) { - if ((empty($albul['users_indirect']) || count(array_intersect($album['users_indirect'], $params['user_id'])) === 0) + /** @phpstan-ignore-next-line */ + if ((empty($album['users_indirect']) || count(array_intersect($album['users_indirect'], $params['user_id'])) === 0) + /** @phpstan-ignore-next-line */ && (empty($album['users']) || count(array_intersect($album['users'], $params['user_id'])) === 0)) { unset($permissions[$album_id]); continue; } } + /** @phpstan-ignore-next-line */ $album['groups'] = !empty($album['groups']) ? array_values(array_unique($album['groups'])) : []; + /** @phpstan-ignore-next-line */ $album['users'] = !empty($album['users']) ? array_values(array_unique($album['users'])) : []; + /** @phpstan-ignore-next-line */ $album['users_indirect'] = !empty($album['users_indirect']) ? array_values(array_unique($album['users_indirect'])) : []; } diff --git a/src/Phyxo/Image/DerivativeImage.php b/src/Phyxo/Image/DerivativeImage.php index d4fbb83e2..678990133 100644 --- a/src/Phyxo/Image/DerivativeImage.php +++ b/src/Phyxo/Image/DerivativeImage.php @@ -21,7 +21,7 @@ */ class DerivativeImage { - private $src_image, $params, $rel_path, $rel_url, $image_std_params; + private $src_image, $params, $image_std_params; public function __construct(SrcImage $src_image, $params, ImageStandardParams $image_std_params) { @@ -147,11 +147,6 @@ private function build($src, &$params, &$rel_path, &$rel_url, &$is_cached = null $rel_url = 'media' . '/' . $loc; } - public function get_path(): string - { - return __DIR__ . '/../../../' . $this->rel_path; - } - public function same_as_source(): bool { return $this->params == null; diff --git a/src/Phyxo/Plugin/Plugins.php b/src/Phyxo/Plugin/Plugins.php index a7c2cb143..de82bc3bf 100644 --- a/src/Phyxo/Plugin/Plugins.php +++ b/src/Phyxo/Plugin/Plugins.php @@ -94,7 +94,7 @@ public function performAction(string $action, string $plugin_id, int $revision = $plugin_maintain->install($this->fs_plugins[$plugin_id]['version'], $error); - if (empty($error)) { + if ($error === '') { $plugin = new Plugin(); $plugin->setId($plugin_id); $plugin->setVersion($this->fs_plugins[$plugin_id]['version']); @@ -124,7 +124,7 @@ public function performAction(string $action, string $plugin_id, int $revision = break; } - if (empty($errors)) { + if ($error === '') { $this->pluginRepository->updateState($plugin_id, Plugin::ACTIVE); } break; diff --git a/src/Phyxo/TabSheet/TabSheet.php b/src/Phyxo/TabSheet/TabSheet.php index 501bf5626..d14a33904 100644 --- a/src/Phyxo/TabSheet/TabSheet.php +++ b/src/Phyxo/TabSheet/TabSheet.php @@ -13,11 +13,10 @@ class TabSheet implements \IteratorAggregate { - private $elements = [], $position; + private $elements = []; public function __construct() { - $this->position = 0; } public function add($name, $caption, $url, $icon = '') diff --git a/src/Phyxo/Theme/DummyThemeMaintain.php b/src/Phyxo/Theme/DummyThemeMaintain.php index 2751a8537..e31183e8e 100644 --- a/src/Phyxo/Theme/DummyThemeMaintain.php +++ b/src/Phyxo/Theme/DummyThemeMaintain.php @@ -15,6 +15,7 @@ class DummyThemeMaintain implements ThemeMaintain { + /** @phpstan-ignore-next-line */ private $theme_id; public function __construct(string $id) diff --git a/src/Phyxo/Theme/Themes.php b/src/Phyxo/Theme/Themes.php index c2d39792e..417e79f2a 100644 --- a/src/Phyxo/Theme/Themes.php +++ b/src/Phyxo/Theme/Themes.php @@ -93,7 +93,7 @@ public function performAction($action, $theme_id): string $theme_maintain->activate($this->fs_themes[$theme_id]['version'], $error); - if (empty($error)) { + if ($error === '') { $theme = new Theme(); $theme->setId($theme_id); $theme->setVersion($this->fs_themes[$theme_id]['version']); diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index 907cb6c36..6d8577914 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -32,14 +32,13 @@ class LoginFormAuthenticator extends AbstractFormLoginAuthenticator { use TargetPathTrait; - private $router, $passwordEncoder, $csrfTokenManager, $userProvider; + private $router, $passwordEncoder, $csrfTokenManager; - public function __construct(RouterInterface $router, UserPasswordEncoderInterface $passwordEncoder, CsrfTokenManagerInterface $crsfTokenManager, UserProvider $userProvider) + public function __construct(RouterInterface $router, UserPasswordEncoderInterface $passwordEncoder, CsrfTokenManagerInterface $crsfTokenManager) { $this->router = $router; $this->passwordEncoder = $passwordEncoder; $this->csrfTokenManager = $crsfTokenManager; - $this->userProvider = $userProvider; } public function start(Request $request, AuthenticationException $authException = null)