diff --git a/features/web/search.feature b/features/web/search.feature index e2407e8ed..90e01eb29 100644 --- a/features/web/search.feature +++ b/features/web/search.feature @@ -59,11 +59,11 @@ Feature: Searching for images When I am on homepage And I follow "Search" Then the select "authors" should contain: - """ - author1 (one photo) - author2 (2 photos) - author3 (one photo) - """ + """ + author1 (one photo) + author2 (2 photos) + author3 (one photo) + """ When I select "author2" from "authors" And I press "Submit" Then I should see photo "photo 2" @@ -75,10 +75,10 @@ Feature: Searching for images When I am on homepage And I follow "Search" Then the select "tags" should contain: - """ - tag 1 (2 photos) - tag 2 (2 photos) - """ + """ + tag 1 (2 photos) + tag 2 (2 photos) + """ When I select "tag 2" from "tags" And I press "Submit" Then I should see photo "photo 1" @@ -91,11 +91,11 @@ Feature: Searching for images When I am on homepage And I follow "Search" Then the select "tags" should contain: - """ - tag 1 (2 photos) - tag 2 (3 photos) - tag 3 (one photo) - """ + """ + tag 1 (2 photos) + tag 2 (3 photos) + tag 3 (one photo) + """ When I select "tag 2" from "tags" And I press "Submit" Then I should see photo "photo 1" diff --git a/src/Controller/Admin/AdminAlbumController.php b/src/Controller/Admin/AdminAlbumController.php index 860db17da..8fd17124b 100644 --- a/src/Controller/Admin/AdminAlbumController.php +++ b/src/Controller/Admin/AdminAlbumController.php @@ -41,7 +41,7 @@ class AdminAlbumController extends AbstractController { private TranslatorInterface $translator; - protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): array + protected function setTabsheet(int $album_id, string $section = 'properties', int $parent_id = null): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('properties', $this->translator->trans('Properties', [], 'admin'), $this->generateUrl('admin_album', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-pencil'); @@ -50,7 +50,7 @@ protected function setTabsheet(int $album_id, string $section = 'properties', in $tabsheet->add('notification', $this->translator->trans('Notification', [], 'admin'), $this->generateUrl('admin_album_notification', ['album_id' => $album_id, 'parent_id' => $parent_id]), 'fa-envelope'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function properties( @@ -234,7 +234,7 @@ public function properties( $tpl_params['CACHE_KEYS'] = Utils::getAdminClientCacheKeys($managerRegistry, ['categories'], $this->generateUrl('homepage')); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options'); $tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet($album_id, 'properties', $parent_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'properties', $parent_id); return $this->render('album_properties.html.twig', $tpl_params); } @@ -363,7 +363,7 @@ public function sort_order( $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options'); $tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin'); $tpl_params['ALBUM_ID'] = $album_id; - $tpl_params = array_merge($this->setTabsheet($album_id, 'sort_order', $parent_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'sort_order', $parent_id); return $this->render('album_sort_order.html.twig', $tpl_params); } @@ -516,7 +516,7 @@ public function permissions( $tpl_params['U_PAGE'] = $this->generateUrl('admin_albums'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options'); $tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet($album_id, 'permissions', $parent_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'permissions', $parent_id); return $this->render('album_permissions.html.twig', $tpl_params); } @@ -603,7 +603,7 @@ public function notification( $tpl_params['U_PAGE'] = $this->generateUrl('admin_albums'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options'); $tpl_params['PAGE_TITLE'] = $translator->trans('Album', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet($album_id, 'notification', $parent_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($album_id, 'notification', $parent_id); return $this->render('album_notification.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminAlbumsController.php b/src/Controller/Admin/AdminAlbumsController.php index 67abe88ee..777cf2ecf 100644 --- a/src/Controller/Admin/AdminAlbumsController.php +++ b/src/Controller/Admin/AdminAlbumsController.php @@ -19,21 +19,22 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminAlbumsController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'list'): array + protected function setTabsheet(string $section = 'list'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('list', $this->translator->trans('List', [], 'admin'), $this->generateUrl('admin_albums'), 'fa-bars'); $tabsheet->add('move', $this->translator->trans('Move', [], 'admin'), $this->generateUrl('admin_albums_move'), 'fa-move'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function list( @@ -43,7 +44,7 @@ public function list( CsrfTokenManagerInterface $csrfTokenManager, TranslatorInterface $translator, ImageAlbumRepository $imageAlbumRepository - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -133,12 +134,12 @@ public function list( $tpl_params['U_PAGE'] = $this->generateUrl('admin_albums'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums'); $tpl_params['PAGE_TITLE'] = $translator->trans('Albums', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('list'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('list'); return $this->render('albums_list.html.twig', $tpl_params); } - public function update(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator) + public function update(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator): Response { if ($request->isMethod('POST')) { if ($request->request->get('submitManualOrder')) { // save manual category ordering @@ -195,7 +196,7 @@ public function update(Request $request, int $parent_id = null, AlbumRepository return $this->redirectToRoute('admin_albums', ['parent_id' => $parent_id]); } - public function move(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator) + public function move(Request $request, int $parent_id = null, AlbumRepository $albumRepository, AlbumMapper $albumMapper, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -226,7 +227,7 @@ public function move(Request $request, int $parent_id = null, AlbumRepository $a $tpl_params['U_PAGE'] = $this->generateUrl('admin_albums_move'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums'); $tpl_params['PAGE_TITLE'] = $translator->trans('Albums', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('move'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('move'); return $this->render('albums_move.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminAlbumsOptionsController.php b/src/Controller/Admin/AdminAlbumsOptionsController.php index 7d3dc46c4..d3db9291c 100644 --- a/src/Controller/Admin/AdminAlbumsOptionsController.php +++ b/src/Controller/Admin/AdminAlbumsOptionsController.php @@ -18,13 +18,14 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; class AdminAlbumsOptionsController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(Conf $conf, string $section = 'status'): array + protected function setTabsheet(Conf $conf, string $section = 'status'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('status', $this->translator->trans('Public / Private', [], 'admin'), $this->generateUrl('admin_albums_options'), 'fa-lock'); @@ -37,10 +38,10 @@ protected function setTabsheet(Conf $conf, string $section = 'status'): array } $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } - public function index(Request $request, string $section, Conf $conf, AlbumMapper $albumMapper, AlbumRepository $albumRepository, TranslatorInterface $translator) + public function index(Request $request, string $section, Conf $conf, AlbumMapper $albumMapper, AlbumRepository $albumRepository, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -83,11 +84,12 @@ public function index(Request $request, string $section, Conf $conf, AlbumMapper $tpl_params['U_PAGE'] = $this->generateUrl('admin_albums_options', ['section' => $section]); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_albums_options'); $tpl_params['PAGE_TITLE'] = $this->translator->trans('Public / Private', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet($conf, $section), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($conf, $section); return $this->render('albums_options.html.twig', $tpl_params); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function getCatsBySection(string $section, AlbumRepository $albumRepository): array { $cats_true = []; diff --git a/src/Controller/Admin/AdminBatchManagerController.php b/src/Controller/Admin/AdminBatchManagerController.php index a4ab92bd0..5e14abde1 100644 --- a/src/Controller/Admin/AdminBatchManagerController.php +++ b/src/Controller/Admin/AdminBatchManagerController.php @@ -50,16 +50,19 @@ public function __construct(AppUserService $appUserService) $this->user = $appUserService->getUser(); } - protected function setTabsheet(string $section = 'global'): array + protected function setTabsheet(string $section = 'global'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('global', $this->translator->trans('global mode', [], 'admin'), $this->generateUrl('admin_batch_manager_global')); $tabsheet->add('unit', $this->translator->trans('unit mode', [], 'admin'), $this->generateUrl('admin_batch_manager_unit')); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } + /** + * @param array> $filter + */ protected function appendFilter(SessionInterface $session, array $filter = []): void { $previous_filter = $this->getFilter($session); @@ -70,6 +73,9 @@ protected function appendFilter(SessionInterface $session, array $filter = []): $session->set('bulk_manager_filter', array_merge($previous_filter, $filter)); } + /** + * @return array> + */ protected function getFilter(SessionInterface $session): array { $filter = $session->has('bulk_manager_filter') ? $session->get('bulk_manager_filter'): []; @@ -415,7 +421,7 @@ public function global( $tpl_params['U_PAGE'] = $this->generateUrl('admin_batch_manager_global'); $tpl_params['F_ACTION'] = $this->generateUrl('admin_batch_manager_global'); $tpl_params['PAGE_TITLE'] = $translator->trans('Site manager', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('global'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('global'); return $this->render('batch_manager_global.html.twig', $tpl_params); } @@ -428,6 +434,9 @@ public function emptyCaddie(Request $request, CaddieRepository $caddieRepository return $this->redirectToRoute('admin_batch_manager_global', ['start' => $request->get('start')]); } + /** + * @param int[] $collection + */ protected function actionOnCollection( Request $request, TagMapper $tagMapper, @@ -438,7 +447,7 @@ protected function actionOnCollection( CaddieRepository $caddieRepository, ImageTagRepository $imageTagRepository, array $collection = [] - ) { + ): ?Response { // if the user tries to apply an action, it means that there is at least 1 photo in the selection if (count($collection) === 0 && !$request->request->get('submitFilter')) { $this->addFlash('error', $this->translator->trans('Select at least one photo', [], 'admin')); @@ -596,6 +605,8 @@ protected function actionOnCollection( if ($redirect) { return $this->redirectToRoute('admin_batch_manager_global'); + } else { + return null; } } @@ -606,6 +617,9 @@ protected function filterFromSession(SessionInterface $session): void } } + /** + * @return array> + */ protected function getFilterSetsFromFilter( SearchMapper $searchMapper, ImageMapper $imageMapper, @@ -630,7 +644,7 @@ protected function getFilterSetsFromFilter( case 'favorites': $user_favorites = []; - foreach ($favoriteRepository->findUserFavorites($this->user->getId(), $this->user->getUserInfos()->getForbiddenCategories()) as $favorite) { + foreach ($favoriteRepository->findUserFavorites($this->user->getId(), $this->user->getUserInfos()->getForbiddenAlbums()) as $favorite) { $user_favorites[] = $favorite->getImage()->geId(); } $filter_sets[] = $user_favorites; @@ -755,7 +769,7 @@ protected function getFilterSetsFromFilter( if (!empty($bulk_manager_filter['tags'])) { $image_ids = []; foreach ($imageMapper->getRepository()->getImageIdsForTags( - $this->user->getUserInfos()->getForbiddenCategories(), + $this->user->getUserInfos()->getForbiddenAlbums(), $bulk_manager_filter['tags'], $bulk_manager_filter['tag_mode'] ) as $image) { @@ -823,16 +837,18 @@ protected function getFilterSetsFromFilter( } if (!empty($bulk_manager_filter['search']) && !empty($bulk_manager_filter['search']['q'])) { + /** @phpstan-ignore-next-line */ $result = $searchMapper->getQuickSearchResults($bulk_manager_filter['search']['q'], $this->user); - if (!empty($result['items']) && !empty($result['qs']['unmatched_terms'])) { - // $tpl_params ??? $template->assign('no_search_results', $result['qs']['unmatched_terms']); - } + // if (!empty($result['items']) && !empty($result['qs']['unmatched_terms'])) { + // // $tpl_params ??? $template->assign('no_search_results', $result['qs']['unmatched_terms']); + // } $filter_sets[] = $result['items']; } return $filter_sets; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function setDimensions(ImageMapper $imageMapper, SessionInterface $session): array { $tpl_params = []; @@ -1169,7 +1185,7 @@ public function unit( $tpl_params['CACHE_KEYS'] = Utils::getAdminClientCacheKeys($managerRegistry, ['tags', 'categories'], $this->generateUrl('homepage')); $tpl_params['ws'] = $this->generateUrl('ws'); - $tpl_params = array_merge($this->setTabsheet('unit'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('unit'); return $this->render('batch_manager_unit.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminCommentsController.php b/src/Controller/Admin/AdminCommentsController.php index 26dbecc9b..114477a00 100644 --- a/src/Controller/Admin/AdminCommentsController.php +++ b/src/Controller/Admin/AdminCommentsController.php @@ -28,14 +28,14 @@ class AdminCommentsController extends AbstractController { private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'all'): array + protected function setTabsheet(string $section = 'all'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('all', $this->translator->trans('All comments', [], 'admin'), $this->generateUrl('admin_comments')); $tabsheet->add('pending', $this->translator->trans('Pending comments', [], 'admin'), $this->generateUrl('admin_comments', ['section' => 'pending'])); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function index( @@ -83,7 +83,7 @@ public function index( $tpl_params['U_PAGE'] = $this->generateUrl('admin_comments', ['section' => $section, 'start' => $start]); $tpl_params['PAGE_TITLE'] = $translator->trans('Comments', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet($section), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($section); $tpl_params['navbar'] = Utils::createNavigationBar( $router, diff --git a/src/Controller/Admin/AdminConfigurationController.php b/src/Controller/Admin/AdminConfigurationController.php index 37217db69..c4d32d51c 100644 --- a/src/Controller/Admin/AdminConfigurationController.php +++ b/src/Controller/Admin/AdminConfigurationController.php @@ -30,8 +30,24 @@ class AdminConfigurationController extends AbstractController { - private $main_checkboxes, $sizes_checkboxes, $comments_checkboxes, $sort_fields, $comments_order, $mail_themes; - private $translator; + /** @var array $main_checkboxes */ + private array $main_checkboxes; + + /** @var array $sizes_checkboxes */ + private $sizes_checkboxes; + + /** @var array $comments_checkboxes */ + private $comments_checkboxes; + + /** @var array $sort_fields */ + private $sort_fields; + + /** @var array $comments_order */ + private $comments_order; + + /** @var array $mail_themes */ + private $mail_themes; + private TranslatorInterface $translator; public function __construct(TranslatorInterface $translator) { @@ -96,7 +112,7 @@ public function __construct(TranslatorInterface $translator) ]; } - protected function setTabsheet(string $section = 'main'): array + protected function setTabsheet(string $section = 'main'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('main', $this->translator->trans('General', [], 'admin'), $this->generateUrl('admin_configuration')); @@ -107,7 +123,7 @@ protected function setTabsheet(string $section = 'main'): array $tabsheet->add('default', $this->translator->trans('Guest Settings', [], 'admin'), $this->generateUrl('admin_configuration_default')); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function index( @@ -121,7 +137,7 @@ public function index( $tpl_params['U_PAGE'] = $this->generateUrl('admin_configuration', ['section' => $section]); $tpl_params['F_ACTION'] = $this->generateUrl('admin_configuration_update', ['section' => $section]); - $tpl_params = array_merge($this->setTabsheet($section), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet($section); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_configuration'); @@ -161,6 +177,7 @@ public function sizeRestore(ImageStandardParams $image_std_params, Conf $conf, T return $this->redirectToRoute('admin_configuration', ['section' => 'sizes']); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function mainConfiguration(Conf $conf): array { $tpl_params = []; @@ -192,6 +209,7 @@ protected function mainConfiguration(Conf $conf): array return $tpl_params; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function commentsConfiguration(Conf $conf): array { $tpl_params = []; @@ -212,7 +230,7 @@ protected function commentsConfiguration(Conf $conf): array public function displayConfiguration(Request $request, Conf $conf, TranslatorInterface $translator): Response { $tpl_params = []; - $tpl_params = array_merge($this->setTabsheet('display'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('display'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_configuration'); $form = $this->createForm(DisplayConfigurationType::class, $conf); @@ -233,6 +251,7 @@ public function displayConfiguration(Request $request, Conf $conf, TranslatorInt return $this->render('configuration_display.html.twig', $tpl_params); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function sizesConfiguration(Conf $conf, ImageStandardParams $image_std_params): array { $tpl_params = []; @@ -289,6 +308,7 @@ protected function sizesConfiguration(Conf $conf, ImageStandardParams $image_std return $tpl_params; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function watermarkConfiguration(Conf $conf, string $themesDir, string $localDir, ImageStandardParams $image_std_params): array { $tpl_params = []; @@ -353,7 +373,7 @@ protected function watermarkConfiguration(Conf $conf, string $themesDir, string public function defaultConfiguration(Request $request, UserMapper $userMapper, UserInfosRepository $userInfosRepository, TranslatorInterface $translator): Response { $tpl_params = []; - $tpl_params = array_merge($this->setTabsheet('default'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('default'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_configuration'); $form = $this->createForm(UserInfosType::class, $userMapper->getDefaultUser()->getUserInfos()); diff --git a/src/Controller/Admin/AdminGroupsController.php b/src/Controller/Admin/AdminGroupsController.php index 28a76a1d6..5e0adbf39 100644 --- a/src/Controller/Admin/AdminGroupsController.php +++ b/src/Controller/Admin/AdminGroupsController.php @@ -19,24 +19,25 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminGroupsController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - public function setTabsheet(string $section = 'list', int $group_id = 0): array + public function setTabsheet(string $section = 'list', int $group_id = 0): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('list', $this->translator->trans('Groups', [], 'admin'), $this->generateUrl('admin_groups'), 'fa-group'); - $tabsheet->add('perm', $this->translator->trans('Permissions', [], 'admin'), $group_id !== 0 ? $this->generateUrl('admin_group_perm', ['group_id' => $group_id]) : null, 'fa-lock'); + $tabsheet->add('perm', $this->translator->trans('Permissions', [], 'admin'), $group_id !== 0 ? $this->generateUrl('admin_group_perm', ['group_id' => $group_id]) : '', 'fa-lock'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } - public function list(Request $request, TranslatorInterface $translator, GroupRepository $groupRepository, CsrfTokenManagerInterface $tokenManager) + public function list(Request $request, TranslatorInterface $translator, GroupRepository $groupRepository, CsrfTokenManagerInterface $tokenManager): Response { $tpl_params = []; $this->translator = $translator; @@ -78,7 +79,7 @@ public function list(Request $request, TranslatorInterface $translator, GroupRep $tpl_params['F_ACTION_RENAME'] = $this->generateUrl('admin_groups_action', ['action' => 'rename']); $tpl_params['F_ACTION_TOGGLE_DEFAULT'] = $this->generateUrl('admin_groups_action', ['action' => 'toggle_default']); $tpl_params['PAGE_TITLE'] = $translator->trans('Groups', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('list'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('list'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_groups'); @@ -93,7 +94,7 @@ public function perm( TranslatorInterface $translator, GroupRepository $groupRepository, CsrfTokenManagerInterface $tokenManager - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -146,14 +147,14 @@ public function perm( $tpl_params['U_PAGE'] = $this->generateUrl('admin_groups'); $tpl_params['PAGE_TITLE'] = $translator->trans('Groups', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('perm', $group_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('perm', $group_id); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_groups'); return $this->render('groups_perm.html.twig', $tpl_params); } - public function action(Request $request, string $action, GroupRepository $groupRepository, TranslatorInterface $translator) + public function action(Request $request, string $action, GroupRepository $groupRepository, TranslatorInterface $translator): Response { $group_selection = $request->request->all()['group_selection']; if (count($group_selection) === 0) { diff --git a/src/Controller/Admin/AdminHistoryController.php b/src/Controller/Admin/AdminHistoryController.php index d2b75ef93..98e4be437 100644 --- a/src/Controller/Admin/AdminHistoryController.php +++ b/src/Controller/Admin/AdminHistoryController.php @@ -47,14 +47,14 @@ public function __construct(ImageStandardParams $image_std_params, TranslatorInt $this->translator = $translator; } - protected function setTabsheet(string $section = 'stats'): array + protected function setTabsheet(string $section = 'stats'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('stats', $this->translator->trans('Statistics', [], 'admin'), $this->generateUrl('admin_history'), 'fa-signal'); $tabsheet->add('search', $this->translator->trans('Search', [], 'admin'), $this->generateUrl('admin_history_search'), 'fa-search'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function stats( @@ -158,7 +158,7 @@ public function stats( } $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_history'); - $tpl_params = array_merge($this->setTabsheet('stats'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('stats'); return $this->render('history_stats.html.twig', $tpl_params); } @@ -233,11 +233,12 @@ public function search( $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_history'); $tpl_params['PAGE_TITLE'] = $this->translator->trans('History', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('search'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('search'); return $this->render('history_search.html.twig', $tpl_params); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function getElementFromSearchRules( SearchRulesModel $rules, int $start, @@ -387,6 +388,7 @@ function ($m) use ($name_of_tag) { ]; } + /** @phpstan-ignore-next-line */ protected function getImageString(ImageStandardParams $image_std_params, History $line, array $image_infos = [], SearchRulesModel $rules = null): string { $image_string = ''; diff --git a/src/Controller/Admin/AdminLanguagesController.php b/src/Controller/Admin/AdminLanguagesController.php index 8c7197edc..09d23cabd 100644 --- a/src/Controller/Admin/AdminLanguagesController.php +++ b/src/Controller/Admin/AdminLanguagesController.php @@ -19,15 +19,15 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminLanguagesController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - public function setTabsheet(string $section = 'installed') + public function setTabsheet(string $section = 'installed'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('installed', $this->translator->trans('Installed Languages', [], 'admin'), $this->generateUrl('admin_languages_installed'), 'fa-language'); @@ -35,7 +35,7 @@ public function setTabsheet(string $section = 'installed') $tabsheet->add('new', $this->translator->trans('Add New Language', [], 'admin'), $this->generateUrl('admin_languages_new'), 'fa-plus-circle'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function installed( @@ -44,7 +44,7 @@ public function installed( TranslatorInterface $translator, LanguageRepository $languageRepository, UserInfosRepository $userInfosRepository - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -106,7 +106,7 @@ public function installed( $tpl_params['U_PAGE'] = $this->generateUrl('admin_languages_installed'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('installed'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('installed'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_languages_installed'); @@ -120,7 +120,7 @@ public function action( LanguageRepository $languageRepository, UserInfosRepository $userInfosRepository, ParameterBagInterface $params - ) { + ): Response { $languages = new Languages($languageRepository, $userMapper->getDefaultLanguage()); $languages->setRootPath($params->get('translator.default_path')); @@ -137,7 +137,7 @@ public function action( return $this->redirectToRoute('admin_languages_installed'); } - public function new(UserMapper $userMapper, Conf $conf, ParameterBagInterface $params, TranslatorInterface $translator, LanguageRepository $languageRepository) + public function new(UserMapper $userMapper, Conf $conf, ParameterBagInterface $params, TranslatorInterface $translator, LanguageRepository $languageRepository): Response { $tpl_params = []; $this->translator = $translator; @@ -164,7 +164,7 @@ public function new(UserMapper $userMapper, Conf $conf, ParameterBagInterface $p $tpl_params['U_PAGE'] = $this->generateUrl('admin_languages_installed'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('new'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('new'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_languages_installed'); @@ -177,7 +177,7 @@ public function install( UserMapper $userMapper, TranslatorInterface $translator, LanguageRepository $languageRepository - ) { + ): Response { if (!$userMapper->isWebmaster()) { $this->addFlash('error', $translator->trans('Webmaster status is required.', [], 'admin')); @@ -207,7 +207,7 @@ public function update( ParameterBagInterface $params, TranslatorInterface $translator, LanguageRepository $languageRepository - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -269,7 +269,7 @@ public function update( $tpl_params['U_PAGE'] = $this->generateUrl('admin_languages_installed'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('update'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('update'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_languages_installed'); $tpl_params['INSTALL_URL'] = $this->generateUrl('admin_languages_installed'); diff --git a/src/Controller/Admin/AdminNotificationController.php b/src/Controller/Admin/AdminNotificationController.php index eebf07886..0f6c8ebb5 100644 --- a/src/Controller/Admin/AdminNotificationController.php +++ b/src/Controller/Admin/AdminNotificationController.php @@ -16,12 +16,15 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminNotificationController extends AbstractController { - private $translator, $authorizationChecker; + private TranslatorInterface $translator; + private AuthorizationCheckerInterface $authorizationChecker; + /** @var array $conf_types */ private $conf_types = [ 'nbm_send_html_mail' => 'boolean', 'nbm_send_mail_as' => 'string', @@ -35,7 +38,7 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker) $this->authorizationChecker = $authorizationChecker; } - protected function setTabsheet(string $section = 'params'): array + protected function setTabsheet(string $section = 'params'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('params', $this->translator->trans('Parameters', [], 'admin'), $this->generateUrl('admin_notification')); @@ -45,10 +48,10 @@ protected function setTabsheet(string $section = 'params'): array } $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } - public function params(Request $request, Conf $conf, Notification $notification, TranslatorInterface $translator) + public function params(Request $request, Conf $conf, Notification $notification, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -79,14 +82,14 @@ public function params(Request $request, Conf $conf, Notification $notification, $tpl_params['U_PAGE'] = $this->generateUrl('admin_notification'); $tpl_params['PAGE_TITLE'] = $translator->trans('Notification', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('params'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('params'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_notification'); return $this->render('notification_by_mail_params.html.twig', $tpl_params); } - public function subscribe(Request $request, Notification $notification, TranslatorInterface $translator) + public function subscribe(Request $request, Notification $notification, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -133,14 +136,14 @@ public function subscribe(Request $request, Notification $notification, Translat $tpl_params['U_PAGE'] = $this->generateUrl('admin_notification'); $tpl_params['PAGE_TITLE'] = $translator->trans('Notification', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('subscribe'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('subscribe'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_notification'); return $this->render('notification_by_mail_subscribe.html.twig', $tpl_params); } - public function send(Request $request, Conf $conf, Notification $notification, TranslatorInterface $translator) + public function send(Request $request, Conf $conf, Notification $notification, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -183,7 +186,7 @@ public function send(Request $request, Conf $conf, Notification $notification, T $tpl_params['U_PAGE'] = $this->generateUrl('admin_notification'); $tpl_params['PAGE_TITLE'] = $translator->trans('Notification', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('send'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('send'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_notification'); diff --git a/src/Controller/Admin/AdminPhotoController.php b/src/Controller/Admin/AdminPhotoController.php index 54a026e5f..800774688 100644 --- a/src/Controller/Admin/AdminPhotoController.php +++ b/src/Controller/Admin/AdminPhotoController.php @@ -36,14 +36,17 @@ class AdminPhotoController extends AbstractController { private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'properties', array $params = []): array + /** + * @param array $params + */ + protected function setTabsheet(string $section = 'properties', array $params = []): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('properties', $this->translator->trans('Properties', [], 'admin'), $this->generateUrl('admin_photo', $params)); $tabsheet->add('coi', $this->translator->trans('Center of interest', [], 'admin'), $this->generateUrl('admin_photo_coi', $params), 'fa-crop'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function edit( @@ -208,15 +211,15 @@ public function edit( $image_albums[] = $image_album->getAlbum()->getId(); } - $authorizeds = array_diff($image_albums, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()); + $authorizeds = array_diff($image_albums, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()); $url_img = ''; if ($category_id && in_array($category_id, $authorizeds)) { - $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'category', 'element_id' => $category_id]); + $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'album', 'element_id' => $category_id]); } else { if (count($authorizeds) > 0) { $album_id = $authorizeds[0]; - $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'category', 'element_id' => $cache_albums[$album_id]->getId()]); + $url_img = $this->generateUrl('picture', ['image_id' => $image_id, 'type' => 'album', 'element_id' => $cache_albums[$album_id]->getId()]); } } @@ -234,7 +237,7 @@ public function edit( $tpl_params['U_PAGE'] = $this->generateUrl('admin_photo', ['image_id' => $image_id, 'category_id' => $category_id]); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_batch_manager_global'); $tpl_params['PAGE_TITLE'] = $translator->trans('Photo', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('properties', ['image_id' => $image_id, 'category_id' => $category_id]), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('properties', ['image_id' => $image_id, 'category_id' => $category_id]); return $this->render('photo_properties.html.twig', $tpl_params); } @@ -265,7 +268,7 @@ public function delete( $image_albums[] = $image_album->getAlbum()->getId(); } - $authorizeds = array_diff($image_albums, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()); + $authorizeds = array_diff($image_albums, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()); if (count($authorizeds) > 0) { return $this->redirectToRoute('admin_album', ['album_id' => $authorizeds[0]]); @@ -350,7 +353,7 @@ public function coi( $tpl_params['U_PAGE'] = $this->generateUrl('admin_photo_coi', ['image_id' => $image_id, 'category_id' => $category_id]); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_batch_manager_global'); $tpl_params['PAGE_TITLE'] = $translator->trans('Photo', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('coi', ['image_id' => $image_id, 'category_id' => $category_id]), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('coi', ['image_id' => $image_id, 'category_id' => $category_id]); return $this->render('photo_coi.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminPhotosController.php b/src/Controller/Admin/AdminPhotosController.php index 4efdcc620..114df0b9a 100644 --- a/src/Controller/Admin/AdminPhotosController.php +++ b/src/Controller/Admin/AdminPhotosController.php @@ -23,14 +23,15 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminPhotosController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'direct', bool $enable_synchronization = false) + protected function setTabsheet(string $section = 'direct', bool $enable_synchronization = false): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('direct', $this->translator->trans('Web Form', [], 'admin'), $this->generateUrl('admin_photos_add', ['section' => 'direct']), 'fa-upload'); @@ -39,7 +40,7 @@ protected function setTabsheet(string $section = 'direct', bool $enable_synchron } $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function direct( @@ -51,7 +52,7 @@ public function direct( TranslatorInterface $translator, ImageMapper $imageMapper, ManagerRegistry $managerRegistry - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -155,12 +156,12 @@ public function direct( $tpl_params['U_PAGE'] = $this->generateUrl('admin_photos_add'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_photos_add'); $tpl_params['PAGE_TITLE'] = $translator->trans('Photo', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('direct', $conf['enable_synchronization']), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('direct', $conf['enable_synchronization']); return $this->render('photos_add_direct.html.twig', $tpl_params); } - public function batch(Request $request, AppUserService $appUserService, ImageRepository $imageRepository, CaddieRepository $caddieRepository) + public function batch(Request $request, AppUserService $appUserService, ImageRepository $imageRepository, CaddieRepository $caddieRepository): Response { $caddieRepository->emptyCaddies($appUserService->getUser()->getId()); foreach ($imageRepository->findBy(['id' => explode(',', $request->request->get('batch'))]) as $image) { diff --git a/src/Controller/Admin/AdminPluginsController.php b/src/Controller/Admin/AdminPluginsController.php index 3748e27df..9bc29b528 100644 --- a/src/Controller/Admin/AdminPluginsController.php +++ b/src/Controller/Admin/AdminPluginsController.php @@ -18,15 +18,15 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminPluginsController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'installed') + protected function setTabsheet(string $section = 'installed'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('installed', $this->translator->trans('Plugin list', [], 'admin'), $this->generateUrl('admin_plugins_installed'), 'fa-sliders'); @@ -34,7 +34,7 @@ protected function setTabsheet(string $section = 'installed') $tabsheet->add('new', $this->translator->trans('Other plugins', [], 'admin'), $this->generateUrl('admin_plugins_new'), 'fa-plus-circle'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function installed( @@ -44,7 +44,7 @@ public function installed( CsrfTokenManagerInterface $csrfTokenManager, ParameterBagInterface $params, TranslatorInterface $translator - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -106,14 +106,14 @@ public function installed( $tpl_params['U_PAGE'] = $this->generateUrl('admin_plugins_installed'); $tpl_params['PAGE_TITLE'] = $translator->trans('Plugins', [], 'admin'); $tpl_params['EXT_TYPE'] = 'plugins'; - $tpl_params = array_merge($this->setTabsheet('installed'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('installed'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_plugins_installed'); return $this->render('plugins_installed.html.twig', $tpl_params); } - public function install(int $revision, PluginRepository $pluginRepository, ParameterBagInterface $params, UserMapper $userMapper, TranslatorInterface $translator) + public function install(int $revision, PluginRepository $pluginRepository, ParameterBagInterface $params, UserMapper $userMapper, TranslatorInterface $translator): Response { if (!$userMapper->isWebmaster()) { $this->addFlash('error', $translator->trans('Webmaster status is required.', [], 'admin')); @@ -144,7 +144,7 @@ public function new( ParameterBagInterface $params, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -176,7 +176,7 @@ public function new( $tpl_params['U_PAGE'] = $this->generateUrl('admin_plugins_new'); $tpl_params['PAGE_TITLE'] = $translator->trans('Plugins', [], 'admin'); $tpl_params['EXT_TYPE'] = 'plugins'; - $tpl_params = array_merge($this->setTabsheet('new'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('new'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_plugins_installed'); @@ -190,7 +190,7 @@ public function update( CsrfTokenManagerInterface $csrfTokenManager, ParameterBagInterface $params, TranslatorInterface $translator - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -251,7 +251,7 @@ public function update( $tpl_params['csrf_token'] = $csrfTokenManager->getToken('authenticate'); $tpl_params['U_PAGE'] = $this->generateUrl('admin_plugins_update'); $tpl_params['PAGE_TITLE'] = $translator->trans('Plugins', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('update'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('update'); $tpl_params['INSTALL_URL'] = $this->generateUrl('admin_plugins_installed'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_plugins_installed'); diff --git a/src/Controller/Admin/AdminRatingController.php b/src/Controller/Admin/AdminRatingController.php index 64cb906f6..4264fb127 100644 --- a/src/Controller/Admin/AdminRatingController.php +++ b/src/Controller/Admin/AdminRatingController.php @@ -31,14 +31,14 @@ class AdminRatingController extends AbstractController { private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'photos'): array + protected function setTabsheet(string $section = 'photos'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('photos', $this->translator->trans('Photos', [], 'admin'), $this->generateUrl('admin_rating')); $tabsheet->add('users', $this->translator->trans('Users', [], 'admin'), $this->generateUrl('admin_rating_users')); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function photos( @@ -170,7 +170,7 @@ public function photos( $tpl_params['U_PAGE'] = $this->generateUrl('admin_rating'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_rating'); $tpl_params['PAGE_TITLE'] = $translator->trans('Rating', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('photos'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('photos'); $tpl_params['WS_RATES_DELETE'] = $this->generateUrl('ws') . '?method=pwg.rates.delete'; return $this->render('rating_photos.html.twig', $tpl_params); @@ -348,11 +348,12 @@ public function users( $tpl_params['U_PAGE'] = $this->generateUrl('admin_rating'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_rating'); $tpl_params['PAGE_TITLE'] = $translator->trans('Rating', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('users'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('users'); return $this->render('rating_users.html.twig', $tpl_params); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function avg_compare(array $a, array $b): int { $d = $a['avg'] - $b['avg']; @@ -360,6 +361,7 @@ protected function avg_compare(array $a, array $b): int return ($d == 0) ? 0 : ($d < 0 ? -1 : 1); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function count_compare(array $a, array $b): int { $d = $a['count'] - $b['count']; @@ -367,6 +369,7 @@ protected function count_compare(array $a, array $b): int return ($d == 0) ? 0 : ($d < 0 ? -1 : 1); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function cv_compare(array $a, array $b): int { $d = $b['cv'] - $a['cv']; //desc @@ -374,6 +377,7 @@ protected function cv_compare(array $a, array $b): int return ($d == 0) ? 0 : ($d < 0 ? -1 : 1); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function consensus_dev_compare(array $a, array $b): int { $d = $b['cd'] - $a['cd']; //desc @@ -381,6 +385,7 @@ protected function consensus_dev_compare(array $a, array $b): int return ($d == 0) ? 0 : ($d < 0 ? -1 : 1); } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function last_rate_compare(array $a, array $b): int { return -strcmp($a['last_date'], $b['last_date']); diff --git a/src/Controller/Admin/AdminTagsController.php b/src/Controller/Admin/AdminTagsController.php index 80760f70a..11682f8d6 100644 --- a/src/Controller/Admin/AdminTagsController.php +++ b/src/Controller/Admin/AdminTagsController.php @@ -19,14 +19,15 @@ use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminTagsController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'all'): array + protected function setTabsheet(string $section = 'all'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('all', $this->translator->trans('All tags', [], 'admin'), $this->generateUrl('admin_tags')); @@ -35,16 +36,15 @@ protected function setTabsheet(string $section = 'all'): array $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function list( - Request $request, CsrfTokenManagerInterface $csrfTokenManager, TranslatorInterface $translator, TagMapper $tagMapper, ImageTagRepository $imageTagRepository - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -98,12 +98,12 @@ public function list( $tpl_params['U_PAGE'] = $this->generateUrl('admin_tags'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_tags'); $tpl_params['PAGE_TITLE'] = $translator->trans('Tags', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('all'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('all'); return $this->render('tags_all.html.twig', $tpl_params); } - public function actions(Request $request, TagMapper $tagMapper, TranslatorInterface $translator) + public function actions(Request $request, TagMapper $tagMapper, TranslatorInterface $translator): Response { if ($request->request->get('action') === 'edit') { $existing_names = []; @@ -219,7 +219,7 @@ public function actions(Request $request, TagMapper $tagMapper, TranslatorInterf return $this->redirectToRoute('admin_tags'); } - public function add(Request $request, TagMapper $tagMapper, TranslatorInterface $translator) + public function add(Request $request, TagMapper $tagMapper, TranslatorInterface $translator): Response { if ($request->request->get('add_tag')) { if (!is_null($tagMapper->getRepository()->findOneBy(['name' => $request->request->get('add_tag')]))) { @@ -238,7 +238,7 @@ public function add(Request $request, TagMapper $tagMapper, TranslatorInterface return $this->redirectToRoute('admin_tags'); } - public function deleteOrphans(TagMapper $tagMapper, TranslatorInterface $translator) + public function deleteOrphans(TagMapper $tagMapper, TranslatorInterface $translator): Response { $tagMapper->deleteOrphanTags(); $this->addFlash('success', $translator->trans('Orphan tags deleted', [], 'admin')); @@ -246,7 +246,7 @@ public function deleteOrphans(TagMapper $tagMapper, TranslatorInterface $transla return $this->redirectToRoute('admin_tags'); } - public function permissions(Request $request, Conf $conf, TagMapper $tagMapper, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager) + public function permissions(Request $request, Conf $conf, TagMapper $tagMapper, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager): Response { $tpl_params = []; $this->translator = $translator; @@ -298,12 +298,12 @@ public function permissions(Request $request, Conf $conf, TagMapper $tagMapper, $tpl_params['U_PAGE'] = $this->generateUrl('admin_tags'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_tags'); $tpl_params['PAGE_TITLE'] = $translator->trans('Tags', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('permissions'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('permissions'); return $this->render('tags_permissions.html.twig', $tpl_params); } - public function pending(Request $request, TagMapper $tagMapper, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager) + public function pending(Request $request, TagMapper $tagMapper, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager): Response { $tpl_params = []; $this->translator = $translator; @@ -326,7 +326,7 @@ public function pending(Request $request, TagMapper $tagMapper, TranslatorInterf $tpl_params['U_PAGE'] = $this->generateUrl('admin_tags_permissions'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_tags'); $tpl_params['PAGE_TITLE'] = $translator->trans('Tags', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('pending'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('pending'); return $this->render('tags_pending.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminThemesController.php b/src/Controller/Admin/AdminThemesController.php index 85b107963..88f96bc1a 100644 --- a/src/Controller/Admin/AdminThemesController.php +++ b/src/Controller/Admin/AdminThemesController.php @@ -19,15 +19,15 @@ use Phyxo\Theme\Themes; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminThemesController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - protected function setTabsheet(string $section = 'installed') + protected function setTabsheet(string $section = 'installed'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('installed', $this->translator->trans('Installed Themes', [], 'admin'), $this->generateUrl('admin_themes_installed'), 'fa-paint-brush'); @@ -35,17 +35,16 @@ protected function setTabsheet(string $section = 'installed') $tabsheet->add('new', $this->translator->trans('Add New Theme', [], 'admin'), $this->generateUrl('admin_themes_new'), 'fa-plus-circle'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function installed( - Request $request, ThemeRepository $themeRepository, UserMapper $userMapper, ParameterBagInterface $params, TranslatorInterface $translator, CsrfTokenManagerInterface $tokenManager - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -150,7 +149,7 @@ public function installed( $tpl_params['U_PAGE'] = $this->generateUrl('admin_themes_installed'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('installed'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('installed'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_themes_installed'); @@ -158,14 +157,13 @@ public function installed( } public function update( - Request $request, UserMapper $userMapper, Conf $conf, CsrfTokenManagerInterface $tokenManager, ThemeRepository $themeRepository, ParameterBagInterface $params, TranslatorInterface $translator - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -220,7 +218,7 @@ public function update( $tpl_params['U_PAGE'] = $this->generateUrl('admin_themes_update'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('update'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('update'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_themes_installed'); @@ -234,7 +232,7 @@ public function action( ThemeRepository $themeRepository, UserInfosRepository $userInfosRepository, ParameterBagInterface $params - ) { + ): Response { $themes = new Themes($themeRepository, $userMapper); $themes->setRootPath($params->get('themes_dir')); @@ -256,7 +254,7 @@ public function action( return $this->redirectToRoute('admin_themes_installed'); } - public function install(int $revision, ParameterBagInterface $params, UserMapper $userMapper, ThemeRepository $themeRepository, TranslatorInterface $translator) + public function install(int $revision, ParameterBagInterface $params, UserMapper $userMapper, ThemeRepository $themeRepository, TranslatorInterface $translator): Response { if (!$userMapper->isWebmaster()) { $this->addFlash('error', $translator->trans('Webmaster status is required.', [], 'admin')); @@ -280,7 +278,7 @@ public function install(int $revision, ParameterBagInterface $params, UserMapper } } - public function new(ThemeRepository $themeRepository, UserMapper $userMapper, Conf $conf, ParameterBagInterface $params, TranslatorInterface $translator) + public function new(ThemeRepository $themeRepository, UserMapper $userMapper, Conf $conf, ParameterBagInterface $params, TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -305,7 +303,7 @@ public function new(ThemeRepository $themeRepository, UserMapper $userMapper, Co $tpl_params['U_PAGE'] = $this->generateUrl('admin_themes_new'); $tpl_params['PAGE_TITLE'] = $translator->trans('Languages', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('new'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('new'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_themes_installed'); diff --git a/src/Controller/Admin/AdminUpdateController.php b/src/Controller/Admin/AdminUpdateController.php index de542a2a4..47adac8a4 100644 --- a/src/Controller/Admin/AdminUpdateController.php +++ b/src/Controller/Admin/AdminUpdateController.php @@ -25,23 +25,24 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminUpdateController extends AbstractController { - private $translator; - private $defaultTheme; + private TranslatorInterface $translator; + private string $defaultTheme; - protected function setTabsheet(string $section = 'core'): array + protected function setTabsheet(string $section = 'core'): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('core', $this->translator->trans('Phyxo Update', [], 'admin'), $this->generateUrl('admin_update')); $tabsheet->add('extensions', $this->translator->trans('Extensions Update', [], 'admin'), $this->generateUrl('admin_update_extensions')); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function core( @@ -61,7 +62,7 @@ public function core( Themes $themes, Languages $languages, int $step = 0 - ) { + ): Response { $tpl_params = []; $tpl_params['missing'] = ['plugins' => '', 'themes' => '', 'languages' => '']; @@ -266,12 +267,12 @@ public function core( $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_update'); $tpl_params['U_PAGE'] = $this->generateUrl('admin_update'); $tpl_params['PAGE_TITLE'] = $translator->trans('Updates', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('core'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('core'); return $this->render('updates_core.html.twig', $tpl_params); } - public function extensions(TranslatorInterface $translator) + public function extensions(TranslatorInterface $translator): Response { $tpl_params = []; $this->translator = $translator; @@ -279,7 +280,7 @@ public function extensions(TranslatorInterface $translator) $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_update'); $tpl_params['U_PAGE'] = $this->generateUrl('admin_update_extensions'); $tpl_params['PAGE_TITLE'] = $translator->trans('Updates', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('extensions'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('extensions'); return $this->render('updates_ext.html.twig', $tpl_params); } diff --git a/src/Controller/Admin/AdminUsersController.php b/src/Controller/Admin/AdminUsersController.php index 722d4e5a4..8a909ec37 100644 --- a/src/Controller/Admin/AdminUsersController.php +++ b/src/Controller/Admin/AdminUsersController.php @@ -19,27 +19,27 @@ use App\Repository\ThemeRepository; use App\Repository\UserInfosRepository; use App\Repository\UserRepository; -use App\Security\AppUser; use App\Security\AppUserService; use Phyxo\Conf; use Phyxo\TabSheet\TabSheet; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; use Symfony\Contracts\Translation\TranslatorInterface; class AdminUsersController extends AbstractController { - private $translator; + private TranslatorInterface $translator; - public function setTabsheet(string $section = 'list', int $user_id = 0): array + public function setTabsheet(string $section = 'list', int $user_id = 0): TabSheet { $tabsheet = new TabSheet(); $tabsheet->add('list', $this->translator->trans('User list', [], 'admin'), $this->generateUrl('admin_users'), 'fa-users'); - $tabsheet->add('perm', $this->translator->trans('Permissions', [], 'admin'), $user_id !== 0 ? $this->generateUrl('admin_user_perm', ['user_id' => $user_id]) : null, 'fa-lock'); + $tabsheet->add('perm', $this->translator->trans('Permissions', [], 'admin'), $user_id !== 0 ? $this->generateUrl('admin_user_perm', ['user_id' => $user_id]) : '', 'fa-lock'); $tabsheet->select($section); - return ['tabsheet' => $tabsheet]; + return $tabsheet; } public function list( @@ -53,7 +53,7 @@ public function list( UserRepository $userRepository, UserInfosRepository $userInfosRepository, GroupRepository $groupRepository - ) { + ): Response { $tpl_params = []; $this->translator = $translator; @@ -146,12 +146,12 @@ public function list( $tpl_params['U_PAGE'] = $this->generateUrl('admin_users'); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_users'); $tpl_params['PAGE_TITLE'] = $translator->trans('Users', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('list'), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('list'); return $this->render('users_list.html.twig', $tpl_params); } - public function perm(Request $request, int $user_id, AlbumMapper $albumMapper, TranslatorInterface $translator, UserRepository $userRepository) + public function perm(Request $request, int $user_id, AlbumMapper $albumMapper, TranslatorInterface $translator, UserRepository $userRepository): Response { $tpl_params = []; $this->translator = $translator; @@ -202,7 +202,7 @@ public function perm(Request $request, int $user_id, AlbumMapper $albumMapper, T $tpl_params['U_PAGE'] = $this->generateUrl('admin_user_perm', ['user_id' => $user_id]); $tpl_params['ACTIVE_MENU'] = $this->generateUrl('admin_users'); $tpl_params['PAGE_TITLE'] = $translator->trans('Users', [], 'admin'); - $tpl_params = array_merge($this->setTabsheet('perm', $user_id), $tpl_params); + $tpl_params['tabsheet'] = $this->setTabsheet('perm', $user_id); return $this->render('user_perm.html.twig', $tpl_params); } diff --git a/src/Controller/AlbumController.php b/src/Controller/AlbumController.php index fc25a787c..700b6b812 100644 --- a/src/Controller/AlbumController.php +++ b/src/Controller/AlbumController.php @@ -51,7 +51,7 @@ public function album( $album = $albumMapper->getRepository()->find($album_id); - if (in_array($album_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (in_array($album_id, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums())) { throw new AccessDeniedHttpException("Access denied to that album"); } @@ -192,7 +192,7 @@ public function album( } $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $order_by) as $image) { + foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $order_by) as $image) { $tpl_params['items'][] = $image['id']; } @@ -254,12 +254,12 @@ public function albumFlat( $album = $albumMapper->getRepository()->find($album_id); $subcat_ids[] = $album->getId(); - foreach ($albumMapper->getRepository()->findAllowedSubAlbums($album->getUppercats(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $sub_album) { + foreach ($albumMapper->getRepository()->findAllowedSubAlbums($album->getUppercats(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $sub_album) { $subcat_ids[] = $sub_album->getId(); } $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $conf['order_by']) as $image) { + foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $conf['order_by']) as $image) { $tpl_params['items'][] = $image['id']; } @@ -319,7 +319,7 @@ public function albumsFlat( $tpl_params['PAGE_TITLE'] = $translator->trans('Albums'); $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->searchDistinctId($appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $conf['order_by']) as $image) { + foreach ($imageMapper->getRepository()->searchDistinctId($appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $conf['order_by']) as $image) { $tpl_params['items'][] = $image['id']; } diff --git a/src/Controller/CalendarController.php b/src/Controller/CalendarController.php index 040fd035a..0b80aeeb1 100644 --- a/src/Controller/CalendarController.php +++ b/src/Controller/CalendarController.php @@ -33,7 +33,7 @@ public function index( $tpl_params['date_type'] = $date_type; $tpl_params['number_of_images'] = 0; - foreach ($imageRepository->countImagesByYear($date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $rowYear) { + foreach ($imageRepository->countImagesByYear($date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $rowYear) { if (is_null($rowYear['year'])) { continue; } @@ -61,7 +61,7 @@ public function index( } krsort($tpl_params['years']); - foreach ($imageRepository->findOneImagePerYear(array_keys($tpl_params['years']), $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageRepository->findOneImagePerYear(array_keys($tpl_params['years']), $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { $tpl_params['years'][$image->getDateByType($date_type)->format('Y')]['image'] = $image; } @@ -92,7 +92,7 @@ public function byYear( } $monthsWithPhotos = []; - foreach ($imageRepository->countImagesByMonth($year, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $rowMonth) { + foreach ($imageRepository->countImagesByMonth($year, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $rowMonth) { $tpl_params['number_of_images'] += $rowMonth['nb_images']; $monthsWithPhotos[] = $this->formatDatePart($rowMonth['month']); $tpl_params['months'][$rowMonth['month']]['nb_images'] = $rowMonth['nb_images']; @@ -106,7 +106,7 @@ public function byYear( ); } - foreach ($imageRepository->findOneImagePerMonth($year, $monthsWithPhotos, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageRepository->findOneImagePerMonth($year, $monthsWithPhotos, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { $tpl_params['months'][$image->getDateByType($date_type)->format('n')]['image'] = $image; } @@ -138,7 +138,7 @@ public function byMonth( $tpl_params['days'] = array_fill(1, (int) $tpl_params['month_date']->format('t'), ['nb_images' => 0]); $daysWithPhotos = []; - foreach ($imageRepository->countImagesByDay($year, $month, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $rowDay) { + foreach ($imageRepository->countImagesByDay($year, $month, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $rowDay) { $tpl_params['number_of_images'] += $rowDay['nb_images']; $daysWithPhotos[] = $this->formatDatePart($rowDay['day']); @@ -154,7 +154,7 @@ public function byMonth( ); } - foreach ($imageRepository->findOneImagePerDay($year, $month, $daysWithPhotos, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageRepository->findOneImagePerDay($year, $month, $daysWithPhotos, $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { $tpl_params['days'][$image->getDateByType($date_type)->format('j')]['image'] = $image; } @@ -175,7 +175,7 @@ public function byDay( int $year, int $month, int $day, - $start = 0 + int $start = 0 ): Response { $tpl_params = []; $tpl_params['date_type'] = $date_type; @@ -188,7 +188,7 @@ public function byDay( $tpl_params['month_label'] = $intl_date_formatter->format($tpl_params['current_day']); $thumbnails = []; - foreach ($imageRepository->findImagesPerDate($tpl_params['current_day'], $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageRepository->findImagesPerDate($tpl_params['current_day'], $date_type, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { $tpl_thumbnail = $image->toArray(); $tpl_thumbnail['image'] = $image; $tpl_thumbnail['URL'] = $this->generateUrl( diff --git a/src/Controller/CommentController.php b/src/Controller/CommentController.php index b9a019197..03a951b53 100644 --- a/src/Controller/CommentController.php +++ b/src/Controller/CommentController.php @@ -40,7 +40,7 @@ public function index( AlbumMapper $albumMapper, int $comment_id, int $start = 0 - ) { + ): Response { $tpl_params = []; $tpl_params['PAGE_TITLE'] = $translator->trans('User comments'); @@ -71,7 +71,7 @@ public function index( $filterParams->setPage(0); } - $forbiddenCategories = $appUserService->getUser()->getUserInfos()->getForbiddenCategories(); + $forbiddenCategories = $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(); if ($filterParams->getAlbum()) { $filterParams->setAlbums($albumMapper->getRepository()->getSubcatIds([$filterParams->getAlbum()->getId()])); @@ -100,7 +100,7 @@ public function index( [ 'image_id' => $comment->getImage()->getId(), 'element_id' => $comment->getImage()->getImageAlbums()->first()->getAlbum()->getId(), - 'type' => 'category' + 'type' => 'album' ] ); diff --git a/src/Controller/CommonController.php b/src/Controller/CommonController.php index a09261048..13f36bb83 100644 --- a/src/Controller/CommonController.php +++ b/src/Controller/CommonController.php @@ -33,6 +33,7 @@ public function __construct(string $defaultTheme, string $themesDir, Conf $conf, $this->phyxoWebsite = $phyxoWebsite; } + /** @phpstan-ignore-next-line */ // @FIX: define return type protected function loadThemeConf(string $theme = null, Conf $core_conf = null): array { if (empty($theme)) { @@ -54,6 +55,7 @@ protected function loadThemeConf(string $theme = null, Conf $core_conf = null): return $extra_params; } + /** @phpstan-ignore-next-line */ // @FIX: define return type public function addThemeParams(Conf $conf): array { $tpl_params = []; diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index 0f22f47e1..758365db1 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -36,7 +36,7 @@ public function download( ): Response { $image = $imageMapper->getRepository()->find($image_id); - if (!$albumMapper->getRepository()->hasAccessToImage($image_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!$albumMapper->getRepository()->hasAccessToImage($image_id, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums())) { throw new AccessDeniedException('Access denied'); } diff --git a/src/Controller/FavoriteController.php b/src/Controller/FavoriteController.php index 0d6fd51b7..cd2b7bcfe 100644 --- a/src/Controller/FavoriteController.php +++ b/src/Controller/FavoriteController.php @@ -20,6 +20,7 @@ use App\Repository\ImageRepository; use App\Security\AppUserService; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -34,7 +35,7 @@ public function index( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; if ($request->cookies->has('category_view')) { @@ -44,7 +45,7 @@ public function index( $tpl_params['TITLE'] = $translator->trans('Your favorites'); $tpl_params['items'] = []; - foreach ($favoriteRepository->findUserFavorites($appUserService->getUser()->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $favorite) { + foreach ($favoriteRepository->findUserFavorites($appUserService->getUser()->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $favorite) { $tpl_params['items'][] = $favorite->getImage()->getId(); } @@ -90,7 +91,7 @@ public function add( AppUserService $appUserService, Request $request, TranslatorInterface $translator - ) { + ): Response { $image = $imageRepository->find($image_id); $favorite = new Favorite(); $favorite->setImage($image); @@ -110,7 +111,7 @@ public function add( return $this->redirectToRoute('favorites'); } - public function remove(int $image_id, FavoriteRepository $favoriteRepository, AppUserService $appUserService, Request $request, TranslatorInterface $translator) + public function remove(int $image_id, FavoriteRepository $favoriteRepository, AppUserService $appUserService, Request $request, TranslatorInterface $translator): Response { $favoriteRepository->deleteUserFavorite($appUserService->getUser()->getId(), $image_id); @@ -127,7 +128,7 @@ public function remove(int $image_id, FavoriteRepository $favoriteRepository, Ap return $this->redirectToRoute('favorites'); } - public function removeAll(FavoriteRepository $favoriteRepository, AppUserService $appUserService) + public function removeAll(FavoriteRepository $favoriteRepository, AppUserService $appUserService): Response { $favoriteRepository->deleteAllUserFavorites($appUserService->getUser()->getId()); diff --git a/src/Controller/IndexController.php b/src/Controller/IndexController.php index f9ca5f80e..77f94e107 100644 --- a/src/Controller/IndexController.php +++ b/src/Controller/IndexController.php @@ -17,6 +17,7 @@ use App\Security\AppUserService; use Phyxo\Image\ImageStandardParams; use Phyxo\Functions\Utils; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -31,7 +32,7 @@ public function mostVisited( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -42,7 +43,7 @@ public function mostVisited( $tpl_params['PAGE_TITLE'] = $translator->trans('Most visited'); $tpl_params['items'] = []; $order_by = [['id', 'DESC']]; - foreach ($imageMapper->getRepository()->findMostVisited($appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $order_by, $conf['top_number']) as $image) { + foreach ($imageMapper->getRepository()->findMostVisited($appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $order_by, $conf['top_number']) as $image) { $tpl_params['items'][] = $image->getId(); } @@ -86,7 +87,7 @@ public function recentPics( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -101,7 +102,7 @@ public function recentPics( $recent_date->sub(new \DateInterval(sprintf('P%dD', $appUserService->getUser()->getUserInfos()->getRecentPeriod()))); $order_by = [['id', 'DESC']]; - foreach ($imageMapper->getRepository()->findRecentImages($recent_date, $appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $order_by) as $image) { + foreach ($imageMapper->getRepository()->findRecentImages($recent_date, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $order_by) as $image) { $tpl_params['items'] = $image->getId(); } @@ -145,7 +146,7 @@ public function bestRated( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -157,7 +158,7 @@ public function bestRated( $order_by = [['rating_score'], ['id', 'DESC']]; $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->findBestRated($conf['top_number'], $appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $order_by) as $image) { + foreach ($imageMapper->getRepository()->findBestRated($conf['top_number'], $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $order_by) as $image) { $tpl_params['items'][] = $image->getId(); } @@ -194,11 +195,11 @@ public function bestRated( return $this->render('thumbnails.html.twig', $tpl_params); } - public function random(ImageMapper $imageMapper, Conf $conf, AppUserService $appUserService) + public function random(ImageMapper $imageMapper, Conf $conf, AppUserService $appUserService): Response { $list = $imageMapper->getRepository()->findRandomImages( min(50, $conf['top_number'], $appUserService->getUser()->getUserInfos()->getNbImagePage()), - $appUserService->getUser()->getUserInfos()->getForbiddenCategories() + $appUserService->getUser()->getUserInfos()->getForbiddenAlbums() ); if (count($list) === 0) { @@ -217,7 +218,7 @@ public function randomList( TranslatorInterface $translator, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -227,7 +228,7 @@ public function randomList( $tpl_params['TITLE'] = $translator->trans('Random photos'); $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->getList(explode(',', $list), $appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageMapper->getRepository()->getList(explode(',', $list), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { $tpl_params['items'][] = $image->getId(); } diff --git a/src/Controller/MediaController.php b/src/Controller/MediaController.php index 84ba37e26..ed0c7a1f1 100644 --- a/src/Controller/MediaController.php +++ b/src/Controller/MediaController.php @@ -45,7 +45,7 @@ public function index( MimeTypeGuesserInterface $mimeTypes, ImageLibraryGuesser $imageLibraryGuesser, AppUserService $appUserService - ) { + ): Response { $this->mimeTypes = $mimeTypes; $image_path = sprintf('%s.%s', $path, $image_extension); @@ -70,7 +70,7 @@ public function index( return new Response('Db file path not found ', 404); } - if (!$this->forAdmin && !$imageRepository->isAuthorizedToUser($image->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!$this->forAdmin && !$imageRepository->isAuthorizedToUser($image->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums())) { return new Response('User not allowed to see that image ', 403); } @@ -228,7 +228,10 @@ public function mediaForAdmin(string $path, string $derivative, string $image_ex ); } - private function url_to_size($s) + /** + * @return array + */ + private function url_to_size(string $s): array { $pos = strpos($s, 'x'); if ($pos === false) { @@ -238,10 +241,13 @@ private function url_to_size($s) return [(int)substr($s, 0, $pos), (int)substr($s, $pos + 1)]; } - private function parse_custom_params($tokens) + /** + * @param array $tokens + */ + private function parse_custom_params(array $tokens): DerivativeParams { if (count($tokens) < 1) { - return new \Exception('Empty array while parsing Sizing', 400); + throw new \Exception('Empty array while parsing Sizing', 400); } $crop = 0; @@ -256,7 +262,7 @@ private function parse_custom_params($tokens) } else { $size = $this->url_to_size($token); if (count($tokens) < 2) { - return new Response('Sizing arr', 400); + throw new \Exception('Sizing arr', 400); } $token = array_shift($tokens); diff --git a/src/Controller/PictureController.php b/src/Controller/PictureController.php index 50ce1152e..d9f6895a1 100644 --- a/src/Controller/PictureController.php +++ b/src/Controller/PictureController.php @@ -89,7 +89,7 @@ public function picture( $history_section = History::SECTION_LIST; $tpl_params['TITLE'] = $translator->trans('Random photos'); $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->searchDistinctId($appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $conf['order_by']) as $image) { + foreach ($imageMapper->getRepository()->searchDistinctId($appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $conf['order_by']) as $image) { $tpl_params['items'][] = $image['id']; } } elseif ($type === 'from_calendar') { @@ -100,12 +100,12 @@ public function picture( } else { $history_section = History::SECTION_ALBUMS; $album = $albumMapper->getRepository()->find((int) $element_id); - if (!is_null($album) && in_array($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!is_null($album) && in_array($album->getId(), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums())) { throw new AccessDeniedHttpException("Access denied to that album"); } $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum((int) $element_id, $appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $conf['order_by']) as $image) { + foreach ($imageMapper->getRepository()->searchDistinctIdInAlbum((int) $element_id, $appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $conf['order_by']) as $image) { $tpl_params['items'][] = $image['id']; } } @@ -601,7 +601,7 @@ public function rate(Request $request, ImageMapper $imageMapper, Conf $conf, Rat $result['score'] = null; if ($request->isMethod('POST')) { - if (!$imageMapper->getRepository()->isAuthorizedToUser($request->request->get('image_id'), $appUserService->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!$imageMapper->getRepository()->isAuthorizedToUser($request->request->get('image_id'), $appUserService->getUser()->getUserInfos()->getForbiddenAlbums())) { throw new AccessDeniedException("Cannot rate that image"); } diff --git a/src/Controller/SearchController.php b/src/Controller/SearchController.php index 07bab0a03..8d36370de 100644 --- a/src/Controller/SearchController.php +++ b/src/Controller/SearchController.php @@ -23,17 +23,18 @@ use App\Repository\TagRepository; use App\Security\AppUserService; use Phyxo\Functions\Utils; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; class SearchController extends CommonController { - public function qsearch(Request $request, Conf $conf, SearchRepository $searchRepository) + public function qsearch(Request $request, Conf $conf, SearchRepository $searchRepository): Response { $tpl_params = []; if (!$request->get('q')) { - return $this->createNotFoundException(); + throw $this->createNotFoundException(); } $tpl_params = array_merge($this->addThemeParams($conf), $tpl_params); @@ -66,7 +67,7 @@ public function search( TranslatorInterface $translator, ImageMapper $imageMapper, AppUserService $appUserService - ) { + ): Response { $tpl_params = []; $tpl_params['PAGE_TITLE'] = $translator->trans('Search'); @@ -82,7 +83,7 @@ public function search( // authors $authors = []; $author_counts = []; - foreach ($imageMapper->getRepository()->findGroupByAuthor($appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($imageMapper->getRepository()->findGroupByAuthor($appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $image) { if (!isset($author_counts[$image->getAuthor()])) { $author_counts[$image->getAuthor()] = 0; } @@ -107,7 +108,7 @@ public function search( $tpl_params['month_list'] = $month_list; $albums = []; - foreach ($albumMapper->getRepository()->findAllowedAlbums($appUserService->getUser()->getUserInfos()->getForbiddenCategories()) as $album) { + foreach ($albumMapper->getRepository()->findAllowedAlbums($appUserService->getUser()->getUserInfos()->getForbiddenAlbums()) as $album) { $albums[] = $album; } $tpl_params = array_merge($tpl_params, $albumMapper->displaySelectAlbumsWrapper($albums, [], 'category_options', true)); @@ -255,12 +256,12 @@ public function searchResults( Conf $conf, SearchRepository $searchRepository, ImageStandardParams $image_std_params, - $search_id, + int $search_id, TranslatorInterface $translator, RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -359,7 +360,7 @@ public function searchRules( SearchRepository $searchRepository, int $search_id, TranslatorInterface $translator - ) { + ): Response { $tpl_params = []; $tpl_params['PAGE_TITLE'] = $translator->trans('Search rules'); diff --git a/src/Controller/TagController.php b/src/Controller/TagController.php index fbe36bc0d..59b956d0b 100644 --- a/src/Controller/TagController.php +++ b/src/Controller/TagController.php @@ -18,16 +18,17 @@ use App\DataMapper\TagMapper; use App\Repository\TagRepository; use App\DataMapper\ImageMapper; -use App\Entity\Tag as EntityTag; +use App\Entity\Tag; use App\Security\AppUserService; use Phyxo\Image\ImageStandardParams; use Phyxo\Functions\Utils; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RouterInterface; use Symfony\Contracts\Translation\TranslatorInterface; class TagController extends CommonController { - public function list(Request $request, AppUserService $appUserService, TagMapper $tagMapper, Conf $conf, MenuBar $menuBar, TranslatorInterface $translator) + public function list(Request $request, AppUserService $appUserService, TagMapper $tagMapper, Conf $conf, MenuBar $menuBar, TranslatorInterface $translator): Response { $tpl_params = []; @@ -139,7 +140,7 @@ public function imagesByTags( RouterInterface $router, AppUserService $appUserService, int $start = 0 - ) { + ): Response { $tpl_params = []; $this->image_std_params = $image_std_params; @@ -163,7 +164,7 @@ function($tag) { $tpl_params['TITLE'] = $this->getTagsContentTitle($translator, $tpl_params['tags']); $tpl_params['items'] = []; - foreach ($imageMapper->getRepository()->getImageIdsForTags($appUserService->getUser()->getUserInfos()->getForbiddenCategories(), $requested_tag_ids) as $image) { + foreach ($imageMapper->getRepository()->getImageIdsForTags($appUserService->getUser()->getUserInfos()->getForbiddenAlbums(), $requested_tag_ids) as $image) { $tpl_params['items'][] = $image->getId(); } @@ -209,6 +210,8 @@ function($tag) { /** * Returns the breadcrumb to be displayed above thumbnails on tag page. + * + * @param Tag[] $tags */ protected function getTagsContentTitle(TranslatorInterface $translator, array $tags = []): string { @@ -229,7 +232,7 @@ protected function getTagsContentTitle(TranslatorInterface $translator, array $t unset($other_tags[$i]); $remove_url = $this->generateUrl( 'images_by_tags', - ['tag_ids' => implode('/', array_map(function(EntityTag $tag) { + ['tag_ids' => implode('/', array_map(function(Tag $tag) { return $tag->toUrl(); }, $other_tags))] ); diff --git a/src/DataMapper/AlbumMapper.php b/src/DataMapper/AlbumMapper.php index 9ac78373b..1670f2f6f 100644 --- a/src/DataMapper/AlbumMapper.php +++ b/src/DataMapper/AlbumMapper.php @@ -109,7 +109,7 @@ protected function insertAlbumInTree(&$categories, $category, $uppercats) protected function getAlbumsMenu(User $user, array $selected_album = []): array { $albums = []; - foreach ($this->getRepository()->getAlbumsForMenu($user->getId(), $user->getUserInfos()->getForbiddenCategories()) as $album) { + foreach ($this->getRepository()->getAlbumsForMenu($user->getId(), $user->getUserInfos()->getForbiddenAlbums()) as $album) { $album_infos = array_merge( $album->toArray(), [ @@ -1069,7 +1069,7 @@ public function getAlbumThumbnails(User $user, array $albums): array } elseif ($album->getRepresentativePictureId()) { // if a representative picture is set, it has priority $image_id = $album->getRepresentativePictureId(); } elseif ($this->conf['allow_random_representative']) { // searching a random representant among elements in sub-categories - if ($random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenCategories())) { + if ($random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums())) { $image_id = $random_image->getId(); } } elseif ($userCacheAlbum->getCountAlbums() > 0 && $userCacheAlbum->getCountImages() > 0) { // searching a random representant among representant of sub-categories @@ -1124,7 +1124,7 @@ public function getInfosOfImages(User $user, array $albums, array $image_ids, Im foreach ($albums as $album) { if ($album->getRepresentativePictureId() === $id) { // searching a random representant among elements in sub-categories - $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenCategories()); + $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums()); if (!is_null($random_image) && !in_array($random_image->getId(), $image_ids)) { $infos_of_images[$random_image->getId()] = [$random_image->toArray(), 'image' => $random_image]; @@ -1152,7 +1152,7 @@ public function getInfosOfImages(User $user, array $albums, array $image_ids, Im foreach ($albums as $album) { if ($id === $album->getRepresentativePictureId()) { // searching a random representant among elements in sub-categories - $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenCategories()); + $random_image = $this->imageRepository->getRandomImageInAlbum($album->getId(), $album->getUppercats(), $user->getUserInfos()->getForbiddenAlbums()); if (!is_null($random_image) && !in_array($random_image->getId(), $image_ids)) { $infos_of_images[$random_image->getId()] = [$random_image->toArray(), 'image' => $random_image]; diff --git a/src/DataMapper/ImageMapper.php b/src/DataMapper/ImageMapper.php index 257cec904..749cbd385 100644 --- a/src/DataMapper/ImageMapper.php +++ b/src/DataMapper/ImageMapper.php @@ -86,11 +86,12 @@ public function getRepository(): ImageRepository } /** + * @param int|string $element_id * @param array{current_day?: DateTimeInterface, date_type?: string, year?: int, month?: int, day?: int } $extra * @param int[] $selection */ /** @phpstan-ignore-next-line */ // @FIX: define return type - public function getPicturesFromSelection(int $element_id, array $selection = [], string $section = '', int $start_id = 0, array $extra = []): array + public function getPicturesFromSelection($element_id, array $selection = [], string $section = '', int $start_id = 0, array $extra = []): array { $tpl_params = []; diff --git a/src/DataMapper/SearchMapper.php b/src/DataMapper/SearchMapper.php index a6ce9f56c..5613963f6 100644 --- a/src/DataMapper/SearchMapper.php +++ b/src/DataMapper/SearchMapper.php @@ -16,7 +16,8 @@ class SearchMapper { - private $imageMapper, $albumRepository; + private ImageMapper $imageMapper; + private AlbumRepository $albumRepository; public function __construct(ImageMapper $imageMapper, AlbumRepository $albumRepository) { @@ -27,6 +28,9 @@ public function __construct(ImageMapper $imageMapper, AlbumRepository $albumRepo /** * Returns an array of 'items' corresponding to the search id. * It can be either a quick search or a regular search. + * + * @param array|array>> $rules + * @return int[] */ public function getSearchResults(array $rules, User $user): array { @@ -37,6 +41,10 @@ public function getSearchResults(array $rules, User $user): array } } + /** + * @param array>> $rules + * @return int[] + */ public function getRegularSearchResults(array $rules, User $user): array { $items = []; @@ -44,9 +52,10 @@ public function getRegularSearchResults(array $rules, User $user): array if (isset($rules['fields']['tags'])) { foreach ($this->imageMapper->getRepository()->getImageIdsForTags( - $user->getUserInfos()->getForbiddenCategories(), - $rules['fields']['tags']['words'], - $rules['fields']['tags']['mode']) as $image) { + $user->getUserInfos()->getForbiddenAlbums(), + $rules['fields']['tags']['words'], + $rules['fields']['tags']['mode'] + ) as $image) { $tag_items[] = $image->getId(); } } @@ -55,7 +64,7 @@ public function getRegularSearchResults(array $rules, User $user): array $rules['fields']['cat']['words'] = array_merge(array_values($rules['fields']['cat']['words']), $this->albumRepository->getSubcatIds($rules['fields']['cat']['words'])); } - foreach ($this->imageMapper->getRepository()->searchImages($rules, $user->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($this->imageMapper->getRepository()->searchImages($rules, $user->getUserInfos()->getForbiddenAlbums()) as $image) { $items[] = $image->getId(); } @@ -77,11 +86,14 @@ public function getRegularSearchResults(array $rules, User $user): array return $items; } + /** + * @return int[] + */ public function getQuickSearchResults(string $q, User $user): array { $items = []; - foreach ($this->imageMapper->getRepository()->qSearchImages($q, $user->getUserInfos()->getForbiddenCategories()) as $image) { + foreach ($this->imageMapper->getRepository()->qSearchImages($q, $user->getUserInfos()->getForbiddenAlbums()) as $image) { $items[] = $image->getId(); } diff --git a/src/DataMapper/TagMapper.php b/src/DataMapper/TagMapper.php index f7c50480e..15bfbbcbf 100644 --- a/src/DataMapper/TagMapper.php +++ b/src/DataMapper/TagMapper.php @@ -28,7 +28,14 @@ class TagMapper { - private $conf, $image_std_params, $router, $metadata, $userCacheRepository, $imageRepository, $tagRepository, $imageTagRepository; + private Conf $conf; + private ImageStandardParams $image_std_params; + private RouterInterface $router; + private Metadata $metadata; + private UserCacheRepository $userCacheRepository; + private ImageRepository $imageRepository; + private TagRepository $tagRepository; + private ImageTagRepository $imageTagRepository; public function __construct( Conf $conf, @@ -72,6 +79,8 @@ public function counterCompare(Tag $a, Tag $b): int /** * Returns all tags even associated to no image. * The list can be filtered by $q + * + * @return Tag[] */ public function getAllTags(string $q = ''): array { @@ -85,6 +94,7 @@ public function getAllTags(string $q = ''): array return $tags; } + /** @phpstan-ignore-next-line */ // @FIX: define return type public function getPendingTags(): array { $tags = []; @@ -117,12 +127,12 @@ public function getPendingTags(): array * The returned list can be a subset of all existing tags due to permissions, * also tags with no images are not returned. * - * @return array [id, name, counter, url_name] + * @return Tag[] */ public function getAvailableTags(User $user): array { $tags = []; - $available_tags = $this->imageTagRepository->getAvailableTags($user->getId(), $user->getUserInfos()->getForbiddenCategories(), $this->conf['show_pending_added_tags'] ?? false); + $available_tags = $this->imageTagRepository->getAvailableTags($user->getId(), $user->getUserInfos()->getForbiddenAlbums(), $this->conf['show_pending_added_tags'] ?? false); foreach ($available_tags as $row) { $tag = $row[0]->getTag(); if (isset($tags[$tag->getId()])) { @@ -133,9 +143,13 @@ public function getAvailableTags(User $user): array $tags[$tag->getId()] = $tag; } - return $tags; + return array_values($tags); } + /** + * @param int[] $excluded_tag_ids + * @return Tag[] + */ public function getRelatedTags(User $user, int $image_id, int $max_tags, array $excluded_tag_ids = []): array { $tags = []; @@ -160,6 +174,11 @@ public function getRelatedTags(User $user, int $image_id, int $max_tags, array $ return $tags; } + /** + * @param int[] $items + * @param int[] $excluded_tag_ids + * @return Tag[] + */ public function getCommonTags(User $user, array $items, int $max_tags, array $excluded_tag_ids = []): array { if (count($items) === 0) { @@ -187,9 +206,10 @@ public function getCommonTags(User $user, array $items, int $max_tags, array $ex /** * Get tags list and surround ids by ~~, for getTagsIds()) to differenciate new tags from existing tags * - * @param boolean $only_user_language - if true, only local name is returned for + * @param Tag[] $tags + * @param bool $only_user_language - if true, only local name is returned for * multilingual tags (if ExtendedDescription plugin is active) - * @return array[] ('id', 'name') + * @return array */ public function prepareTagsListForUI(array $tags, $only_user_language = true) : array { @@ -280,6 +300,9 @@ public function tagIdFromTagName(string $tag_name) : int /** * Add new tags to a set of images. + * + * @param int[] $tag_ids + * @param int[] $image_ids */ public function addTags(array $tag_ids, array $image_ids, User $user): void { @@ -334,7 +357,7 @@ public function deleteTags(array $tag_ids): void /** * Set tags of images. Overwrites all existing associations. * - * @param array $tags_of - keys are image ids, values are array of tag ids + * @param array> $tags_of - keys are image ids, values are array of tag ids */ public function setTagsOf(array $tags_of, User $user): void { @@ -382,6 +405,9 @@ public function deleteOrphanTags(): void } } + /** + * @param int[] $tag_ids + */ public function associateTags(array $tag_ids, int $image_id, User $user): void { if (count($tag_ids) === 0) { @@ -400,8 +426,10 @@ public function associateTags(array $tag_ids, int $image_id, User $user): void $this->invalidateUserCacheNbTags(); } - // @param $elements is an array of tags indexed by image_id - public function rejectTags(array $elements) + /** + * @param array $elements is an array of tags indexed by image_id + */ + public function rejectTags(array $elements): void { if (empty($elements)) { return; @@ -409,7 +437,9 @@ public function rejectTags(array $elements) $this->imageTagRepository->deleteImageTags($elements); } - // @param $elements in an array of tags indexed by image_id + /** + * @param array> $elements is in an array of tags indexed by image_id + */ public function validateTags(array $elements): void { if (count($elements) === 0) { @@ -424,6 +454,9 @@ public function validateTags(array $elements): void $this->invalidateUserCacheNbTags(); } + /** + * @param int[] $tag_ids + */ public function dissociateTags(array $tag_ids, int $image_id): void { if (count($tag_ids) === 0) { @@ -435,6 +468,8 @@ public function dissociateTags(array $tag_ids, int $image_id): void /** * Mark tags as to be validated for addition or deletion. + * + * @param int[] $tags_ids */ public function toBeValidatedTags(Image $image, array $tags_ids, User $user, int $status, bool $validated = false): void { @@ -469,6 +504,8 @@ public function toBeValidatedTags(Image $image, array $tags_ids, User $user, int /** * Sync all metadata of a list of images. * Metadata are fetched from original files and saved in database. + * + * @param int[] $ids */ public function sync_metadata(array $ids, User $user): void { @@ -529,8 +566,8 @@ public function invalidateUserCacheNbTags(): void * calculation method avoid having very different levels for tags having * nearly the same count when set are small. * - * @param array $tags at least [id, counter] - * @return array [..., level] + * @param array $tags + * @return Tag[] */ public function addLevelToTags(array $tags = [], int $tags_levels = 5) : array { diff --git a/src/DataMapper/UserMapper.php b/src/DataMapper/UserMapper.php index 169c84280..775df8aa2 100644 --- a/src/DataMapper/UserMapper.php +++ b/src/DataMapper/UserMapper.php @@ -12,6 +12,7 @@ namespace App\DataMapper; use App\Entity\User; +use App\Entity\UserInfos; use App\Repository\UserCacheRepository; use App\Repository\UserRepository; use App\Repository\UserInfosRepository; @@ -28,9 +29,27 @@ class UserMapper { - private $appUserService, $authorizationChecker, $tagMapper, $themeRepository, $userRepository, $userInfosRepository, $userMailNotificationRepository; - private $defaultLanguage, $defaultTheme, $themesDir, $default_user, $default_user_retrieved = false, $commentRepository, $imageTagRepository; - private $webmaster, $webmaster_retrieved = false, $userFeedRepository, $userCacheRepository, $userCacheAlbumRepository, $caddieRepository, $favoriteRepository; + private AppUserService $appUserService; + private AuthorizationCheckerInterface $authorizationChecker; + private TagMapper $tagMapper; + private ThemeRepository $themeRepository; + private UserRepository $userRepository; + private UserInfosRepository $userInfosRepository; + private UserMailNotificationRepository $userMailNotificationRepository; + private string $defaultLanguage; + private string $defaultTheme; + private string $themesDir; + private User $default_user; + private bool $default_user_retrieved = false; + private CommentRepository $commentRepository; + private ImageTagRepository $imageTagRepository; + private User $webmaster; + private bool $webmaster_retrieved = false; + private UserFeedRepository $userFeedRepository; + private UserCacheRepository $userCacheRepository; + private UserCacheAlbumRepository $userCacheAlbumRepository; + private CaddieRepository $caddieRepository; + private FavoriteRepository $favoriteRepository; public function __construct( AuthorizationCheckerInterface $authorizationChecker, @@ -96,11 +115,11 @@ public function getWebmaster(): User public function getDefaultUser(): ?User { if (!$this->default_user_retrieved) { - $this->default_user = $this->userInfosRepository->findOneByStatus(User::STATUS_GUEST); + $this->default_user = $this->userInfosRepository->findOneBy(['status' => User::STATUS_GUEST])->getUser(); $this->default_user_retrieved = true; } - return $this->default_user->getUser(); + return $this->default_user; } public function setDefaultTheme(string $theme_id): void @@ -167,7 +186,7 @@ public function getNumberAvailableTags(): int */ public function getNumberAvailableComments(): int { - $number_of_available_comments = $this->commentRepository->countAvailableComments($this->getUser()->getUserInfos()->getForbiddenCategories(), $this->isAdmin()); + $number_of_available_comments = $this->commentRepository->countAvailableComments($this->getUser()->getUserInfos()->getForbiddenAlbums(), $this->isAdmin()); $this->userCacheRepository->invalidateNumberAvailableComments($this->getUser()->getId()); diff --git a/src/Entity/UserCache.php b/src/Entity/UserCache.php index 50fbccc4c..a51de633e 100644 --- a/src/Entity/UserCache.php +++ b/src/Entity/UserCache.php @@ -26,52 +26,52 @@ class UserCache * @ORM\Id * @ORM\OneToOne(targetEntity=User::class, inversedBy="userCache", cascade={"persist", "remove"}) */ - private $user; + private User $user; /** * @ORM\Column(type="boolean") */ - private $need_update = true; + private bool $need_update = true; /** * @ORM\Column(type="integer", nullable=true) */ - private $cache_update_time; + private ?int $cache_update_time; /** - * @ORM\Column(type="text") + * @ORM\Column(name="forbidden_categories", type="text") */ - private $forbidden_categories = '[]'; + private string $forbidden_albums = '[]'; /** * @ORM\Column(type="integer", nullable=true) */ - private $nb_total_images = 0; + private ?int $nb_total_images = 0; /** * @ORM\Column(type="datetime", nullable=true) */ - private $last_photo_date; + private ?\DateTimeInterface $last_photo_date; /** * @ORM\Column(type="integer", nullable=true) */ - private $nb_available_tags = 0; + private ?int $nb_available_tags = 0; /** * @ORM\Column(type="integer", nullable=true) */ - private $nb_available_comments = 0; + private ?int $nb_available_comments = 0; /** * @ORM\Column(type="string", length=255) */ - private $image_access_type = self::ACCESS_NOT_IN; + private string $image_access_type = self::ACCESS_NOT_IN; /** * @ORM\Column(type="text", nullable=true) */ - private $image_access_list = '[]'; + private ?string $image_access_list = '[]'; public function getUser(): ?User { @@ -109,14 +109,20 @@ public function setCacheUpdateTime(?int $cache_update_time): self return $this; } - public function getForbiddenCategories(): array + /** + * @return int[] + */ + public function getForbiddenAlbums(): array { - return json_decode($this->forbidden_categories, true); + return json_decode($this->forbidden_albums, true); } - public function setForbiddenCategories(array $forbidden_categories = []): self + /** + * @param int[] $forbidden_albums + */ + public function setForbiddenAlbums(array $forbidden_albums = []): self { - $this->forbidden_categories = json_encode($forbidden_categories); + $this->forbidden_albums = json_encode($forbidden_albums); return $this; } @@ -181,11 +187,17 @@ public function setImageAccessType(string $image_access_type): self return $this; } + /** + * @return int[] + */ public function getImageAccessList(): array { return json_decode($this->image_access_list, true); } + /** + * @param int[] $image_access_list + */ public function setImageAccessList(array $image_access_list = []): self { $this->image_access_list = json_encode($image_access_list); diff --git a/src/Entity/UserInfos.php b/src/Entity/UserInfos.php index 7f20d8611..82db2fc61 100644 --- a/src/Entity/UserInfos.php +++ b/src/Entity/UserInfos.php @@ -20,85 +20,94 @@ */ class UserInfos { - private $nb_total_images; - private $forbidden_categories = [], $image_access_list = [], $image_access_type = 'NOT IN'; + private int $nb_total_images; + /** + * @var int[] $forbidden_albums + */ + private array $forbidden_albums = []; + /** + * @var int[] $image_access_list + */ + private array $image_access_list = []; + private string $image_access_type = 'NOT IN'; /** * @ORM\Id * @ORM\OneToOne(targetEntity=User::class, inversedBy="userInfos", cascade={"persist", "remove"}) * @ORM\JoinColumn(name="user_id", nullable=false) + * @var User $user */ private $user; /** * @ORM\Column(type="string", length=50) */ - private $status; + private string $status; /** * @ORM\Column(type="integer") */ - private $nb_image_page = 15; + private int $nb_image_page = 15; /** * @ORM\Column(type="string", length=255) */ - private $theme; + private string $theme; /** * @ORM\Column(type="string", length=50) */ - private $language; + private string $language; /** * @ORM\Column(type="datetime", nullable=true) */ - private $registration_date; + private ?\DateTimeInterface $registration_date; /** * @ORM\Column(type="integer", nullable=true) */ - private $level = 0; + private ?int $level = 0; /** * @ORM\Column(type="integer") */ - private $recent_period = 7; + private int $recent_period = 7; /** * @ORM\Column(type="boolean") */ - private $expand = false; + private bool $expand = false; /** * @ORM\Column(type="boolean") */ - private $show_nb_comments = false; + private bool $show_nb_comments = false; /** * @ORM\Column(type="boolean") */ - private $show_nb_hits = false; + private bool $show_nb_hits = false; /** * @ORM\Column(type="boolean") */ - private $enabled_high = true; + private bool $enabled_high = true; /** * @ORM\Column(name="lastmodified", type="datetime", nullable=true) */ - private $last_modified; + private ?\DateTimeInterface $last_modified; /** * @ORM\Column(type="string", length=255, nullable=true) */ - private $activation_key; + private ?string $activation_key; /** * @ORM\Column(type="datetime", nullable=true) */ - private $activation_key_expire; + private ?\DateTimeInterface $activation_key_expire; public function getStatus(): ?string { @@ -220,23 +229,35 @@ public function setExpand(bool $expand): self return $this; } - public function getForbiddenCategories(): array + /** + * @return int[] + */ + public function getForbiddenAlbums(): array { - return $this->forbidden_categories; + return $this->forbidden_albums; } - public function setForbiddenCategories(array $forbidden_categories = []): self + /** + * @param int[] $forbidden_albums + */ + public function setForbiddenAlbums(array $forbidden_albums = []): self { - $this->forbidden_categories = $forbidden_categories; + $this->forbidden_albums = $forbidden_albums; return $this; } + /** + * @return int[] + */ public function getImageAccessList(): array { return $this->image_access_list; } + /** + * @param int[] $image_access_list + */ public function setImageAccessList(array $image_access_list = []): self { $this->image_access_list = $image_access_list; @@ -292,6 +313,9 @@ public function setEnabledHigh(bool $enabled_high): self return $this; } + /** + * @return array{nb_image_page: int, language: string, expand: bool, show_nb_comments: bool, show_nb_hits: bool, recent_period: int, theme: string, enabled_high: bool, level: int} + */ public function toArray(): array { return [ @@ -307,6 +331,9 @@ public function toArray(): array ]; } + /** + * @param array{nb_image_page: int, language: string, expand: bool, show_nb_comments: bool, show_nb_hits: bool, recent_period: int, theme: string, enabled_high: bool, level: int} $data + */ public function fromArray(array $data): void { $this->setNbImagePage($data['nb_image_page']); diff --git a/src/Form/CommentFilterType.php b/src/Form/CommentFilterType.php index 089a3213b..10560a1c4 100644 --- a/src/Form/CommentFilterType.php +++ b/src/Form/CommentFilterType.php @@ -25,7 +25,7 @@ class CommentFilterType extends AbstractType { - private $appUserService; + private AppUserService $appUserService; public function __construct(AppUserService $appUserService) { @@ -67,7 +67,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void [ 'class' => Album::class, 'query_builder' => function(AlbumRepository $albumRepository) { - return $albumRepository->getQueryBuilderForFindAllowedAlbums($this->appUserService->getUser()->getUserInfos()->getForbiddenCategories()); + return $albumRepository->getQueryBuilderForFindAllowedAlbums($this->appUserService->getUser()->getUserInfos()->getForbiddenAlbums()); }, 'choice_label' => 'name', 'choice_value' => 'id', diff --git a/src/Notification.php b/src/Notification.php index 1aa404b85..4e6973aea 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -17,6 +17,10 @@ use App\Repository\UserMailNotificationRepository; use App\Repository\UserInfosRepository; use App\DataMapper\UserMapper; +use App\Entity\Album; +use App\Entity\Comment; +use App\Entity\Image; +use App\Entity\User; use App\Entity\UserMailNotification; use Phyxo\Image\DerivativeImage; use Phyxo\Image\ImageStandardParams; @@ -31,11 +35,22 @@ class Notification { - private $conf, $userMapper, $albumMapper, $router, $commentRepository, $imageMapper; - private $env, $mailer, $translator, $userMailNotificationRepository, $userInfosRepository; - - /** @phpstan-ignore-next-line */ - private $infos = [], $errors = []; + private Conf $conf; + private UserMapper $userMapper; + private AlbumMapper $albumMapper; + private RouterInterface $router; + private CommentRepository $commentRepository; + private ImageMapper $imageMapper; + /** @var array $env */ + private array $env; + private MailerInterface $mailer; + private TranslatorInterface $translator; + private UserMailNotificationRepository $userMailNotificationRepository; + private UserInfosRepository $userInfosRepository; + /** @var string[] $infos */ + private array $infos = []; + /** @var string[] $errors */ + private array $errors = []; public function __construct( Conf $conf, @@ -77,15 +92,17 @@ public function __construct( */ public function nb_new_comments(\DateTimeInterface $start = null, \DateTimeInterface $end = null): int { - return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end, $count_only = true); + return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } /** * Returns new comments between two dates. + * + * @return Comment[] */ public function new_comments(\DateTimeInterface $start = null, \DateTimeInterface $end = null): array { - return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end); + return $this->commentRepository->getNewComments($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } /** @@ -101,31 +118,35 @@ public function nb_unvalidated_comments(\DateTimeInterface $start = null, \DateT */ public function nb_new_elements(\DateTimeInterface $start = null, \DateTimeInterface $end = null): int { - return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end, $count_only = true); + return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } /** * Returns new photos between two dates + * + * @return Image[] */ public function new_elements(\DateTimeInterface $start = null, \DateTimeInterface $end = null): array { - return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end); + return $this->imageMapper->getRepository()->getNewElements($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } /** * Returns number of updated albums between two dates. */ - public function nb_updated_categories(\DateTimeInterface $start = null, \DateTimeInterface $end = null): int + public function nb_updated_albums(\DateTimeInterface $start = null, \DateTimeInterface $end = null): int { - return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end, $count_only = true); + return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end, $count_only = true); } /** - * Returns updated categories between two dates. + * Returns updated albums between two dates. + * + * @return Album[] */ - public function updated_categories(\DateTimeInterface $start = null, \DateTimeInterface $end = null): array + public function updated_albums(\DateTimeInterface $start = null, \DateTimeInterface $end = null): array { - return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenCategories(), $start, $end); + return $this->imageMapper->getRepository()->getUpdatedAlbums($this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums(), $start, $end); } /** @@ -138,6 +159,8 @@ public function nb_new_users(\DateTimeInterface $start = null, \DateTimeInterfac /** * Returns new users between two dates. + * + * @return User[] */ public function new_users(\DateTimeInterface $start = null, \DateTimeInterface $end = null) { @@ -155,14 +178,17 @@ public function new_users(\DateTimeInterface $start = null, \DateTimeInterface $ public function news_exists(\DateTimeInterface $start = null, \DateTimeInterface $end = null): bool { return (($this->nb_new_comments($start, $end) > 0) || ($this->nb_new_elements($start, $end) > 0) - || ($this->nb_updated_categories($start, $end) > 0) || (($this->userMapper->isAdmin()) + || ($this->nb_updated_albums($start, $end) > 0) || (($this->userMapper->isAdmin()) && ($this->nb_unvalidated_comments($start, $end) > 0)) || (($this->userMapper->isAdmin()) && ($this->nb_new_users($start, $end) > 0))); } /** * Formats a news line and adds it to the array (e.g. '5 new elements') + * + * @param string[] $news + * @return string[] */ - public function add_news_line(array &$news, int $count, string $lang_key, string $url = '', bool $add_url = false) + public function add_news_line(array $news, int $count, string $lang_key, string $url = '', bool $add_url = false): array { if ($count > 0) { $line = $this->translator->trans($lang_key, ['count' => $count]); @@ -171,6 +197,8 @@ public function add_news_line(array &$news, int $count, string $lang_key, string } $news[] = $line; } + + return $news; } /** @@ -183,14 +211,14 @@ public function add_news_line(array &$news, int $count, string $lang_key, string * * @param bool $exclude_img_cats if true, no info about new images/categories * @param bool $add_url add html link around news - * @return array + * @return string[] */ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = null, bool $exclude_img_cats = false, bool $add_url = false): array { $news = []; if (!$exclude_img_cats) { - $this->add_news_line( + $news = $this->add_news_line( $news, $this->nb_new_elements($start, $end), 'number_of_new_photos', @@ -200,16 +228,16 @@ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = } if (!$exclude_img_cats) { - $this->add_news_line( + $news = $this->add_news_line( $news, - $this->nb_updated_categories($start, $end), + $this->nb_updated_albums($start, $end), 'number_of_albums_updated', $this->router->generate('recent_cats', [], UrlGeneratorInterface::ABSOLUTE_URL), $add_url ); } - $this->add_news_line( + $news = $this->add_news_line( $news, $this->nb_new_comments($start, $end), 'number_of_new_comments', @@ -218,7 +246,7 @@ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = ); if ($this->userMapper->isAdmin()) { - $this->add_news_line( + $news = $this->add_news_line( $news, $this->nb_unvalidated_comments($start, $end), 'number_of_new_comments_to_validate', @@ -226,7 +254,7 @@ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = $add_url ); - $this->add_news_line( + $news = $this->add_news_line( $news, $this->nb_new_users($start, $end), 'number_of_new_users', @@ -245,14 +273,15 @@ public function news(\DateTimeInterface $start = null, \DateTimeInterface $end = * @param int $max_elements maximum number of elements per date * @param int $max_cats maximum number of categories per date */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function get_recent_post_dates(int $max_dates, int $max_elements, int $max_cats): array { - $dates = $this->imageMapper->getRepository()->getRecentPostedImages($max_dates, $this->userMapper->getUser()->getUserInfos()->getForbiddenCategories()); + $dates = $this->imageMapper->getRepository()->getRecentPostedImages($max_dates, $this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums()); for ($i = 0; $i < count($dates); $i++) { if ($max_elements > 0) { // get some thumbnails ... $ids = []; - foreach ($this->imageMapper->getRepository()->findRandomImages($max_elements, $this->userMapper->getUser()->getUserInfos()->getForbiddenCategories()) as $id) { + foreach ($this->imageMapper->getRepository()->findRandomImages($max_elements, $this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums()) as $id) { $ids[] = $id; } $elements = []; @@ -263,7 +292,7 @@ public function get_recent_post_dates(int $max_dates, int $max_elements, int $ma } if ($max_cats > 0) { // get some albums ... - $dates[$i]['categories'] = $this->imageMapper->getRepository()->getRecentImages($dates[$i]['date_available'], $max_cats, $this->userMapper->getUser()->getUserInfos()->getForbiddenCategories()); + $dates[$i]['categories'] = $this->imageMapper->getRepository()->getRecentImages($dates[$i]['date_available'], $max_cats, $this->userMapper->getUser()->getUserInfos()->getForbiddenAlbums()); } } @@ -275,6 +304,7 @@ public function get_recent_post_dates(int $max_dates, int $max_elements, int $ma * Same as get_recent_post_dates() but parameters as an indexed array. * @see get_recent_post_dates() */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function get_recent_post_dates_array(array $args): array { return $this->get_recent_post_dates( @@ -289,8 +319,8 @@ public function get_recent_post_dates_array(array $args): array * @todo clean up HTML output, currently messy and invalid ! * * @param array $date_detail returned value of get_recent_post_dates() - * @return string */ + /** @phpstan-ignore-next-line */ public function get_html_description_recent_post_date(array $date_detail, array $picture_ext): string { $description = '
    '; @@ -344,9 +374,9 @@ public function get_html_description_recent_post_date(array $date_detail, array * Returns title about recently published elements grouped by post date. * * @param array $date_detail returned value of get_recent_post_dates() - * @return string */ - public function get_title_recent_post_date($date_detail) + /** @phpstan-ignore-next-line */ + public function get_title_recent_post_date($date_detail): string { $english_months = [1 => "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; @@ -363,7 +393,7 @@ public function get_title_recent_post_date($date_detail) * * @return true, if it's timeout */ - public function check_sendmail_timeout() + public function check_sendmail_timeout(): bool { $this->env['is_sendmail_timeout'] = ((microtime(true) - $this->env['start_time']) > $this->env['sendmail_timeout']); @@ -375,9 +405,10 @@ public function check_sendmail_timeout() * * Type are the type of list 'subscribe', 'send' * - * return array of users + * @return User[] */ - public function get_user_notifications($action, $check_key_list = [], ?bool $enabled_filter_value = null) + /** @phpstan-ignore-next-line */ + public function get_user_notifications(string $action, array $check_key_list = [], ?bool $enabled_filter_value = null): array { if (in_array($action, ['subscribe', 'send'])) { if ($action == 'send') { @@ -395,10 +426,8 @@ public function get_user_notifications($action, $check_key_list = [], ?bool $ena /* * Begin of use nbm environment * Prepare and save current environment and initialize data in order to send mail - * - * Return none */ - public function begin_users_env_nbm($is_to_send_mail = false) + public function begin_users_env_nbm(bool $is_to_send_mail = false): void { // Save $user, $lang_info and $lang arrays $this->env['save_user'] = $this->userMapper->getUser(); @@ -429,34 +458,23 @@ public function begin_users_env_nbm($is_to_send_mail = false) } } - /* - * Inc Counter success - * - * Return none - */ - public function inc_mail_sent_success($nbm_user) + // Inc Counter success + /** @phpstan-ignore-next-line */ + public function inc_mail_sent_success($nbm_user): void { $this->env['sent_mail_count'] += 1; $this->infos[] = sprintf($this->env['msg_info'], $nbm_user->getUser()->getUsername(), $nbm_user->getUser()->getMailAddress()); } - /* - * Inc Counter failed - * - * Return none - */ - public function inc_mail_sent_failed($nbm_user) + // Inc Counter failed + /** @phpstan-ignore-next-line */ + public function inc_mail_sent_failed($nbm_user): void { $this->env['error_on_mail_count'] += 1; $this->errors[] = sprintf($this->env['msg_error'], $nbm_user->getUser()->getUsername(), $nbm_user->getUser()->getMailAddress()); } - /* - * Display Counter Info - * - * Return none - */ - public function display_counter_info() + public function display_counter_info(): void { if ($this->env['error_on_mail_count'] != 0) { $this->errors[] = $this->translator->trans('number_of_mails_not_sent', ['count' => $this->env['error_on_mail_count']]); @@ -473,6 +491,10 @@ public function display_counter_info() } } + /** + * @return string[] + */ + /** @phpstan-ignore-next-line */ public function assign_vars_nbm_mail_content($nbm_user): array { return [ @@ -490,9 +512,10 @@ public function assign_vars_nbm_mail_content($nbm_user): array * is_subscribe define if action=subscribe or unsubscribe * check_key list where action will be done * - * @return check_key list treated + * @return string[] check_key list treated */ - public function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, bool $is_subscribe = false, $check_key_list = []) + /** @phpstan-ignore-next-line */ + public function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, bool $is_subscribe = false, $check_key_list = []): array { $check_key_treated = []; $updated_data_count = 0; @@ -588,9 +611,10 @@ public function do_subscribe_unsubscribe_notification_by_mail($is_admin_request, * * check_key list where action will be done * - * @return check_key list treated + * @return string[] check_key list treated */ - public function unsubscribe_notification_by_mail($is_admin_request, $check_key_list = []) + /** @phpstan-ignore-next-line */ + public function unsubscribe_notification_by_mail($is_admin_request, $check_key_list = []): array { return $this->do_subscribe_unsubscribe_notification_by_mail($is_admin_request, false, $check_key_list); } @@ -600,9 +624,10 @@ public function unsubscribe_notification_by_mail($is_admin_request, $check_key_l * * check_key list where action will be done * - * @return check_key list treated + * @return string[] check_key list treated */ - public function subscribe_notification_by_mail($is_admin_request, $check_key_list = []) + /** @phpstan-ignore-next-line */ + public function subscribe_notification_by_mail($is_admin_request, $check_key_list = []): array { return $this->do_subscribe_unsubscribe_notification_by_mail($is_admin_request, true, $check_key_list); } @@ -612,9 +637,9 @@ public function subscribe_notification_by_mail($is_admin_request, $check_key_lis * * @param $post_keyname: key of check_key post array * @param check_key_treated: array of check_key treated - * @return none */ - public function do_timeout_treatment($post_keyname, $check_key_treated = []) + /** @phpstan-ignore-next-line */ + public function do_timeout_treatment($post_keyname, $check_key_treated = []): void { if ($this->env['is_sendmail_timeout']) { if (isset($_POST[$post_keyname])) { @@ -633,7 +658,7 @@ public function do_timeout_treatment($post_keyname, $check_key_treated = []) } // Inserting News users - public function insert_new_data_user_mail_notification() + public function insert_new_data_user_mail_notification(): void { $new_users = $this->userMailNotificationRepository->findUsersWithNoMailNotificationInfos(); @@ -671,6 +696,7 @@ public function insert_new_data_user_mail_notification() * Return list of "selected" users for 'list_to_send' * Return list of "treated" check_key for 'send' */ + /** @phpstan-ignore-next-line */ // @FIX: define return type public function do_action_send_mail_notification($action = 'list_to_send', $check_key_list = [], $customize_mail_content = '') { $return_list = []; @@ -820,6 +846,7 @@ public function do_action_send_mail_notification($action = 'list_to_send', $chec return $return_list; } + /** @phpstan-ignore-next-line */ protected function sendMail(array $to, array $from, string $subject, array $params): void { $tpl_params = [ @@ -844,4 +871,20 @@ protected function sendMail(array $to, array $from, string $subject, array $para $this->mailer->send($message); } + + /** + * @return string[] + */ + public function getInfos(): array + { + return $this->infos; + } + + /** + * @return string[] + */ + public function getErrors(): array + { + return $this->errors; + } } diff --git a/src/Phyxo/Functions/Ws/Category.php b/src/Phyxo/Functions/Ws/Category.php index 7bac2fd0b..2096471ee 100644 --- a/src/Phyxo/Functions/Ws/Category.php +++ b/src/Phyxo/Functions/Ws/Category.php @@ -41,7 +41,7 @@ public static function getImages($params, Server $service) //------------------------------------------------- get the related categories $album_ids = []; - $forbidden_categories = $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories(); + $forbidden_categories = $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums(); $albumsList = null; if ($params['recursive']) { @@ -89,7 +89,7 @@ public static function getList($params, Server $service) if ($params['public']) { $public_and_visible = true; } elseif ($service->getUserMapper()->isAdmin()) { - $forbidden_categories = $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories(); + $forbidden_categories = $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums(); } $albumsList = null; diff --git a/src/Phyxo/Functions/Ws/Image.php b/src/Phyxo/Functions/Ws/Image.php index 48a6a0a3f..61f041160 100644 --- a/src/Phyxo/Functions/Ws/Image.php +++ b/src/Phyxo/Functions/Ws/Image.php @@ -39,7 +39,7 @@ class Image */ public static function addComment($params, Server $service) { - if (!$service->getImageMapper()->getRepository()->isAuthorizedToUser($params['image_id'], $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!$service->getImageMapper()->getRepository()->isAuthorizedToUser($params['image_id'], $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums())) { return new Error(Server::WS_ERR_INVALID_PARAM, 'Invalid image_id or access denied'); } @@ -89,7 +89,7 @@ public static function getInfo($params, Server $service) //-------------------------------------------------------- related categories $is_commentable = false; $related_categories = []; - foreach ($service->getAlbumMapper()->getRepository()->findRelative($image->getId(), $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories()) as $album) { + foreach ($service->getAlbumMapper()->getRepository()->findRelative($image->getId(), $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums()) as $album) { $is_commentable = $album->isCommentable(); $album_infos = array_merge( $album->toArray(), @@ -194,7 +194,7 @@ public static function getInfo($params, Server $service) */ public static function rate($params, Server $service) { - if (!$service->getImageMapper()->getRepository()->isAuthorizedToUser($params['image_id'], $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories())) { + if (!$service->getImageMapper()->getRepository()->isAuthorizedToUser($params['image_id'], $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums())) { return new Error(Server::WS_ERR_INVALID_PARAM, 'Invalid image_id or access denied'); } @@ -223,7 +223,7 @@ public static function search($params, Server $service) $search_result = $service->getSearchMapper()->getQuickSearchResults($params['query'], $service->getUserMapper()->getUser()); $image_ids = array_slice( - $search_result['items'], + $search_result, $params['page'] * $params['per_page'], $params['per_page'] ); @@ -244,7 +244,7 @@ public static function search($params, Server $service) 'page' => $params['page'], 'per_page' => $params['per_page'], 'count' => count($images), - 'total_count' => count($search_result['items']), + 'total_count' => count($search_result), ], 'images' => $images, ]; diff --git a/src/Phyxo/Functions/Ws/Tag.php b/src/Phyxo/Functions/Ws/Tag.php index e3022c84d..0e4e4d4b3 100644 --- a/src/Phyxo/Functions/Ws/Tag.php +++ b/src/Phyxo/Functions/Ws/Tag.php @@ -83,7 +83,7 @@ public static function getImages($params, Server $service) $image_ids = []; foreach ($service->getImageMapper()->getRepository()->getImageIdsForTags( - $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenCategories(), + $service->getUserMapper()->getUser()->getUserInfos()->getForbiddenAlbums(), $tag_ids, $params['tag_mode_and'] ? 'AND' : 'OR' ) as $image) { diff --git a/src/Phyxo/TabSheet/TabSheet.php b/src/Phyxo/TabSheet/TabSheet.php index d14a33904..dd1c7a987 100644 --- a/src/Phyxo/TabSheet/TabSheet.php +++ b/src/Phyxo/TabSheet/TabSheet.php @@ -11,15 +11,16 @@ namespace Phyxo\TabSheet; +use Traversable; + class TabSheet implements \IteratorAggregate { + /** + * @var array + */ private $elements = []; - public function __construct() - { - } - - public function add($name, $caption, $url, $icon = '') + public function add(string $name, string $caption, string $url, string $icon = ''): void { if (!isset($this->elements[$name])) { $this->elements[$name] = [ @@ -28,32 +29,24 @@ public function add($name, $caption, $url, $icon = '') 'selected' => false, 'icon' => $icon, ]; - - return true; } - - return false; } - public function delete($name) + public function delete(string $name): void { if (isset($this->elements[$name])) { unset($this->elements[$name]); - - return true; } - - return false; } - public function select($name) + public function select(string $name): void { if (!empty($this->elements[$name])) { $this->elements[$name]['selected'] = true; } } - public function getIterator() + public function getIterator(): Traversable { return new \ArrayIterator($this->elements); } diff --git a/src/Security/UserProvider.php b/src/Security/UserProvider.php index f2c9ec807..aa9cb4410 100644 --- a/src/Security/UserProvider.php +++ b/src/Security/UserProvider.php @@ -28,7 +28,12 @@ class UserProvider implements UserProviderInterface { - private $userRepository, $imageAlbumRepository, $imageRepository, $albumMapper, $userCacheRepository, $userCacheAlbumRepository; + private UserRepository $userRepository; + private ImageAlbumRepository $imageAlbumRepository; + private ImageRepository $imageRepository; + private AlbumMapper $albumMapper; + private UserCacheRepository $userCacheRepository; + private UserCacheAlbumRepository $userCacheAlbumRepository; public function __construct( UserRepository $userRepository, @@ -86,7 +91,7 @@ public function refreshUser(UserInterface $user): User private function fetchUser(string $username, bool $force_refresh = false): ?User { // @TODO : find a way to cash some request: if ($this->user_data === null || $force_refresh) -> tests failed - $user = $this->userRepository->findOneByUsername($username); + $user = $this->userRepository->findOneBy(['username' => $username]); // pretend it returns a User on success, null if there is no user if (is_null($user)) { @@ -94,7 +99,7 @@ private function fetchUser(string $username, bool $force_refresh = false): ?User } $userCache = $this->getUserCacheInfos($user); - $user->getUserInfos()->setForbiddenCategories($userCache->getForbiddenCategories()); + $user->getUserInfos()->setForbiddenAlbums($userCache->getForbiddenAlbums()); $user->getUserInfos()->setImageAccessList($userCache->getImageAccessList()); $user->getUserInfos()->setImageAccessType($userCache->getImageAccessType()); $user->getUserInfos()->setNbTotalImages($userCache->getNbTotalImages()); @@ -112,7 +117,7 @@ private function fetchUserByActivationKey(string $key): ?User } $userCache = $this->getUserCacheInfos($user); - $user->getUserInfos()->setForbiddenCategories($userCache->getForbiddenCategories()); + $user->getUserInfos()->setForbiddenAlbums($userCache->getForbiddenAlbums()); $user->getUserInfos()->setImageAccessList($userCache->getImageAccessList()); $user->getUserInfos()->setImageAccessType($userCache->getImageAccessType()); $user->getUserInfos()->setNbTotalImages($userCache->getNbTotalImages()); @@ -131,22 +136,22 @@ private function getUserCacheInfos(User $user): UserCache $userCache->setCacheUpdateTime(time()); $userCache->setNeedUpdate(false); - $forbidden_categories = $this->calculatePermissions($user->getId(), $is_admin); + $forbidden_albums = $this->calculatePermissions($user->getId(), $is_admin); /* now we build the list of forbidden images (this list does not contain - * images that are not in at least an authorized category) + * images that are not in at least an authorized album) */ $forbidden_image_ids = []; - foreach ($this->imageRepository->getForbiddenImages($forbidden_categories, $user->getUserInfos()->getLevel()) as $image) { + foreach ($this->imageRepository->getForbiddenImages($forbidden_albums, $user->getUserInfos()->getLevel()) as $image) { $forbidden_image_ids[] = $image->getId(); } $userCache->setImageAccessType(UserCache::ACCESS_NOT_IN); $userCache->setImageAccessList($forbidden_image_ids); - $userCache->setNbTotalImages($this->imageAlbumRepository->countTotalImages(UserCache::ACCESS_NOT_IN, $forbidden_categories, $forbidden_image_ids)); + $userCache->setNbTotalImages($this->imageAlbumRepository->countTotalImages(UserCache::ACCESS_NOT_IN, $forbidden_albums, $forbidden_image_ids)); // now we update user cache albums - $user_cache_albums = $this->albumMapper->getComputedAlbums($user->getUserInfos()->getLevel(), $forbidden_categories); + $user_cache_albums = $this->albumMapper->getComputedAlbums($user->getUserInfos()->getLevel(), $forbidden_albums); if (!$is_admin) { // for non admins we forbid albums with no image (feature 1053) $forbidden_ids = []; @@ -157,7 +162,7 @@ private function getUserCacheInfos(User $user): UserCache } } if (count($forbidden_ids) > 0) { - $forbidden_categories = array_merge($forbidden_categories, $forbidden_ids); + $forbidden_albums = array_merge($forbidden_albums, $forbidden_ids); } } @@ -179,7 +184,7 @@ private function getUserCacheInfos(User $user): UserCache // update user cache $userCache->setUser($user); - $userCache->setForbiddenCategories($forbidden_categories); + $userCache->setForbiddenAlbums($forbidden_albums); $this->userCacheRepository->addOrUpdateUserCache($userCache); } @@ -193,10 +198,13 @@ private function getUserCacheInfos(User $user): UserCache * the groups the user belongs to minus the albums directly authorized * to the user. */ + /** + * @return int[] + */ protected function calculatePermissions(int $user_id, bool $is_admin = false): array { $private_albums = []; - foreach ($this->albumMapper->getRepository()->findByStatus(Album::STATUS_PRIVATE) as $album) { + foreach ($this->albumMapper->getRepository()->findBy(['status' => Album::STATUS_PRIVATE]) as $album) { $private_albums[] = $album->getId(); } @@ -219,7 +227,7 @@ protected function calculatePermissions(int $user_id, bool $is_admin = false): a // if user is not an admin, locked albums are forbidden if (!$is_admin) { $locked_albums = []; - foreach ($this->albumMapper->getRepository()->findByVisible(false) as $album) { + foreach ($this->albumMapper->getRepository()->findBy(['visible' => false]) as $album) { $locked_albums[] = $album->getId(); } $forbidden_albums = array_merge($forbidden_albums, $locked_albums); diff --git a/tests/Behat/FeatureContext.php b/tests/Behat/FeatureContext.php index eb39bdb38..3fcf6b272 100644 --- a/tests/Behat/FeatureContext.php +++ b/tests/Behat/FeatureContext.php @@ -77,7 +77,7 @@ public function iShouldNotBeAllowedToGoToAProtectedPage(): void */ public function iShouldNotBeAllowedToGoToAlbum(string $album_name): void { - $this->visit($this->getContainer()->get('router')->generate('album', ['category_id' => $this->storage->get('album_' . $album_name)->getId()])); + $this->visit($this->getContainer()->get('router')->generate('album', ['album_id' => $this->storage->get('album_' . $album_name)->getId()])); $this->getMink()->assertSession()->statusCodeEquals(403); $this->getMink()->assertSession()->pageTextContains('The server returned a "403 Forbidden".'); }