diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bc8d27fd34..312b77f929 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8088,24 +8088,6 @@ parameters: count: 1 path: src/lib/Tab/TabGroup.php - - - message: '#^Method Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:evaluate\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Tab/URLManagement/LinkManagerTab.php - - - - message: '#^Property Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:\$notificationHandler is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: src/lib/Tab/URLManagement/LinkManagerTab.php - - - - message: '#^Property Ibexa\\AdminUi\\Tab\\URLManagement\\LinkManagerTab\:\:\$submitHandler is never read, only written\.$#' - identifier: property.onlyWritten - count: 1 - path: src/lib/Tab/URLManagement/LinkManagerTab.php - - message: '#^Cannot access property \$query on Symfony\\Component\\HttpFoundation\\Request\|null\.$#' identifier: property.nonObject diff --git a/src/bundle/Controller/LinkManagerController.php b/src/bundle/Controller/LinkManagerController.php index 96d8a8592a..e17407ea93 100644 --- a/src/bundle/Controller/LinkManagerController.php +++ b/src/bundle/Controller/LinkManagerController.php @@ -25,40 +25,17 @@ final class LinkManagerController extends Controller { - public const DEFAULT_MAX_PER_PAGE = 10; + public const int DEFAULT_MAX_PER_PAGE = 10; - private URLService $urlService; - - private FormFactory $formFactory; - - private SubmitHandler $submitHandler; - - private TranslatableNotificationHandlerInterface $notificationHandler; - - /** - * @param \Ibexa\Contracts\Core\Repository\URLService $urlService - * @param \Ibexa\AdminUi\Form\Factory\FormFactory $formFactory - * @param \Ibexa\AdminUi\Form\SubmitHandler $submitHandler - * @param \Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface $notificationHandler - */ public function __construct( - URLService $urlService, - FormFactory $formFactory, - SubmitHandler $submitHandler, - TranslatableNotificationHandlerInterface $notificationHandler + private readonly URLService $urlService, + private readonly FormFactory $formFactory, + private readonly SubmitHandler $submitHandler, + private readonly TranslatableNotificationHandlerInterface $notificationHandler ) { - $this->urlService = $urlService; - $this->formFactory = $formFactory; - $this->submitHandler = $submitHandler; - $this->notificationHandler = $notificationHandler; } /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param int $urlId - * - * @return \Symfony\Component\HttpFoundation\Response - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ @@ -107,11 +84,6 @@ public function editAction(Request $request, int $urlId): Response } /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param int $urlId - * - * @return \Symfony\Component\HttpFoundation\Response - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ @@ -123,9 +95,7 @@ public function viewAction(Request $request, int $urlId): Response $usages->setCurrentPage($request->query->getInt('page', 1)); $usages->setMaxPerPage($request->query->getInt('limit', self::DEFAULT_MAX_PER_PAGE)); - $editForm = $this->formFactory->contentEdit( - new ContentEditData() - ); + $editForm = $this->formFactory->contentEdit(new ContentEditData()); return $this->render('@ibexadesign/link_manager/view.html.twig', [ 'url' => $url, diff --git a/src/bundle/Resources/views/themes/admin/link_manager/list.html.twig b/src/bundle/Resources/views/themes/admin/link_manager/list.html.twig index 8397939780..c78ad9d9f9 100644 --- a/src/bundle/Resources/views/themes/admin/link_manager/list.html.twig +++ b/src/bundle/Resources/views/themes/admin/link_manager/list.html.twig @@ -14,7 +14,6 @@ {{ form_label(form.status) }} {{ form_widget(form.status) }} - {{ form_widget(form.page, { attr: { value: '1' }}) }} {{ form_end(form) }} @@ -81,8 +80,7 @@ {% if urls.haveToPaginate %} {% include '@ibexadesign/ui/pagination.html.twig' with { - 'pager': urls, - 'paginaton_params' : {'pageParameter': '[search_data][page]'} + 'pager': urls } %} {% endif %} diff --git a/src/lib/Form/Data/URL/URLListData.php b/src/lib/Form/Data/URL/URLListData.php index 747d49260d..086c2f1956 100644 --- a/src/lib/Form/Data/URL/URLListData.php +++ b/src/lib/Form/Data/URL/URLListData.php @@ -10,17 +10,17 @@ use Ibexa\Contracts\Core\Repository\Values\ValueObject; -class URLListData extends ValueObject +final class URLListData extends ValueObject { - /** @var string|null */ - public $searchQuery; + public ?string $searchQuery; - /** @var bool|null */ - public $status; + public ?bool $status; - /** @var int */ - public $page = 1; - - /** @var int */ - public $limit = 10; + public function __construct( + ?string $searchQuery = null, + ?bool $status = null, + ) { + $this->searchQuery = $searchQuery; + $this->status = $status; + } } diff --git a/src/lib/Form/Data/URL/URLUpdateData.php b/src/lib/Form/Data/URL/URLUpdateData.php index de60affc50..17a26c00ce 100644 --- a/src/lib/Form/Data/URL/URLUpdateData.php +++ b/src/lib/Form/Data/URL/URLUpdateData.php @@ -10,8 +10,7 @@ use Ibexa\Contracts\Core\Repository\Values\URL\URLUpdateStruct; -class URLUpdateData extends URLUpdateStruct +final class URLUpdateData extends URLUpdateStruct { - /** @var int */ - public $id; + public int $id; } diff --git a/src/lib/Form/Type/URL/URLListType.php b/src/lib/Form/Type/URL/URLListType.php index a0788c716b..5468ad51c0 100644 --- a/src/lib/Form/Type/URL/URLListType.php +++ b/src/lib/Form/Type/URL/URLListType.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Form\Type\URL; @@ -11,32 +12,17 @@ use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\SearchType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * URL list form. - */ -class URLListType extends AbstractType +final class URLListType extends AbstractType { - private TranslatorInterface $translator; - - /** - * URLListType constructor. - * - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } - /** - * {@inheritdoc} - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('status', ChoiceType::class, [ @@ -65,14 +51,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('searchQuery', SearchType::class, [ 'required' => false, ]); - - $builder->add('limit', HiddenType::class); - $builder->add('page', HiddenType::class); } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ @@ -81,17 +61,11 @@ public function configureOptions(OptionsResolver $resolver): void ]); } - /** - * {@inheritdoc} - */ public function getName(): string { return $this->getBlockPrefix(); } - /** - * {@inheritdoc} - */ public function getBlockPrefix(): string { return 'ezplatform_content_forms_url_list'; diff --git a/src/lib/Pagination/Pagerfanta/URLSearchAdapter.php b/src/lib/Pagination/Pagerfanta/URLSearchAdapter.php index 7070f1c329..2fc9b0b588 100644 --- a/src/lib/Pagination/Pagerfanta/URLSearchAdapter.php +++ b/src/lib/Pagination/Pagerfanta/URLSearchAdapter.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Pagination\Pagerfanta; @@ -14,22 +15,12 @@ /** * @implements \Pagerfanta\Adapter\AdapterInterface<\Ibexa\Contracts\Core\Repository\Values\URL\URL> */ -class URLSearchAdapter implements AdapterInterface +final readonly class URLSearchAdapter implements AdapterInterface { - private URLQuery $query; - - private URLService $urlService; - - /** - * UrlSearchAdapter constructor. - * - * @param \Ibexa\Contracts\Core\Repository\Values\URL\URLQuery $query - * @param \Ibexa\Contracts\Core\Repository\URLService $urlService - */ - public function __construct(URLQuery $query, URLService $urlService) - { - $this->query = $query; - $this->urlService = $urlService; + public function __construct( + private URLQuery $query, + private URLService $urlService + ) { } /** diff --git a/src/lib/Tab/URLManagement/LinkManagerTab.php b/src/lib/Tab/URLManagement/LinkManagerTab.php index 3ea16a7ba3..ee80f57420 100644 --- a/src/lib/Tab/URLManagement/LinkManagerTab.php +++ b/src/lib/Tab/URLManagement/LinkManagerTab.php @@ -10,9 +10,7 @@ use Ibexa\AdminUi\Form\Data\URL\URLListData; use Ibexa\AdminUi\Form\Factory\FormFactory; -use Ibexa\AdminUi\Form\SubmitHandler; use Ibexa\AdminUi\Pagination\Pagerfanta\URLSearchAdapter; -use Ibexa\Contracts\AdminUi\Notification\TranslatableNotificationHandlerInterface; use Ibexa\Contracts\AdminUi\Tab\AbstractTab; use Ibexa\Contracts\AdminUi\Tab\ConditionalTabInterface; use Ibexa\Contracts\AdminUi\Tab\OrderedTabInterface; @@ -31,39 +29,18 @@ class LinkManagerTab extends AbstractTab implements OrderedTabInterface, ConditionalTabInterface { - public const URI_FRAGMENT = 'ibexa-tab-link-manager-link-manager'; - private const DEFAULT_MAX_PER_PAGE = 10; - - private URLService $urlService; - - private FormFactory $formFactory; - - private SubmitHandler $submitHandler; - - private TranslatableNotificationHandlerInterface $notificationHandler; - - private RequestStack $requestStack; - - private PermissionResolver $permissionResolver; + public const string URI_FRAGMENT = 'ibexa-tab-link-manager-link-manager'; + private const int DEFAULT_MAX_PER_PAGE = 10; public function __construct( Environment $twig, TranslatorInterface $translator, - URLService $urlService, - FormFactory $formFactory, - SubmitHandler $submitHandler, - TranslatableNotificationHandlerInterface $notificationHandler, - RequestStack $request, - PermissionResolver $permissionResolver + private readonly URLService $urlService, + private readonly FormFactory $formFactory, + private readonly RequestStack $requestStack, + private readonly PermissionResolver $permissionResolver ) { parent::__construct($twig, $translator); - - $this->urlService = $urlService; - $this->formFactory = $formFactory; - $this->submitHandler = $submitHandler; - $this->notificationHandler = $notificationHandler; - $this->requestStack = $request; - $this->permissionResolver = $permissionResolver; } public function getIdentifier(): string @@ -83,9 +60,7 @@ public function getOrder(): int } /** - * @param array $parameters - * - * @return bool + * @param array $parameters * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ @@ -103,19 +78,26 @@ public function renderView(array $parameters): string 'csrf_protection' => false, ]); - $form->handleRequest($this->requestStack->getCurrentRequest()); + $request = $this->requestStack->getCurrentRequest(); + $form->handleRequest($request); if ($form->isSubmitted() && !$form->isValid()) { throw new BadRequestHttpException(); } - $urls = new Pagerfanta(new URLSearchAdapter( - $this->buildListQuery($data), - $this->urlService - )); + $urls = new Pagerfanta( + new URLSearchAdapter( + $this->buildListQuery($data), + $this->urlService + ) + ); + + $page = $request !== null + ? $request->query->getInt('page', 1) + : 1; - $urls->setCurrentPage($data->page); - $urls->setMaxPerPage($data->limit ? $data->limit : self::DEFAULT_MAX_PER_PAGE); + $urls->setCurrentPage($page); + $urls->setMaxPerPage(self::DEFAULT_MAX_PER_PAGE); return $this->twig->render('@ibexadesign/link_manager/list.html.twig', [ 'form' => $form->createView(), @@ -124,13 +106,6 @@ public function renderView(array $parameters): string ]); } - /** - * Builds URL criteria from list data. - * - * @param \Ibexa\AdminUi\Form\Data\URL\URLListData $data - * - * @return \Ibexa\Contracts\Core\Repository\Values\URL\URLQuery - */ private function buildListQuery(URLListData $data): URLQuery { $query = new URLQuery();