Skip to content

Commit 090631e

Browse files
committed
IBX-9727: Added type-hints and adapted codebase to PHP8+
1 parent b93a84f commit 090631e

File tree

72 files changed

+455
-1123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+455
-1123
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 338 deletions
Large diffs are not rendered by default.

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ parameters:
99
paths:
1010
- src
1111
- tests
12+
ignoreErrors:
13+
-
14+
message: "#^Cannot call method (log|debug|info|notice|warning|error|critical|alert|emergency)\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"

src/bundle/Resources/config/services/events.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
Ibexa\AdminUi\EventListener\AdminExceptionListener:
3333
arguments:
3434
$siteAccessGroups: '%ibexa.site_access.groups%'
35-
$kernelProjectDir: '%kernel.project_dir%'
35+
$rootDir: '%kernel.project_dir%'
3636
$kernelEnvironment: '%kernel.environment%'
3737
$encoreTagRenderer: '@webpack_encore.tag_renderer'
3838
$entrypointLookupCollection: '@webpack_encore.entrypoint_lookup_collection'

src/lib/Component/Content/ContentEditMetaFieldsComponent.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,18 @@
1515
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition;
1616
use Twig\Environment;
1717

18-
class ContentEditMetaFieldsComponent implements ComponentInterface
18+
final readonly class ContentEditMetaFieldsComponent implements ComponentInterface
1919
{
20-
private const NO_CONTENT = '';
21-
22-
private Environment $twig;
23-
24-
private ConfigResolverInterface $configResolver;
20+
private const string NO_CONTENT = '';
2521

2622
public function __construct(
27-
Environment $twig,
28-
ConfigResolverInterface $configResolver
23+
private Environment $twig,
24+
private ConfigResolverInterface $configResolver
2925
) {
30-
$this->twig = $twig;
31-
$this->configResolver = $configResolver;
3226
}
3327

3428
/**
3529
* @param array<string, mixed> $parameters
36-
*
37-
* @return string
3830
*/
3931
public function render(array $parameters = []): string
4032
{
@@ -84,8 +76,8 @@ private function getMetaFieldDefinitionCollection(ContentType $contentType): Fie
8476
'admin_ui_forms.content_edit.meta_field_groups_list'
8577
);
8678

87-
return $contentType->fieldDefinitions->filter(
88-
static fn (FieldDefinition $field): bool => in_array($field->fieldGroup, $metaFieldGroups, true),
79+
return $contentType->getFieldDefinitions()->filter(
80+
static fn (FieldDefinition $field): bool => in_array($field->getFieldGroup(), $metaFieldGroups, true),
8981
);
9082
}
9183

src/lib/Component/Content/PreviewUnavailableTwigComponent.php

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,17 @@
1616
use Ibexa\Contracts\TwigComponents\ComponentInterface;
1717
use Twig\Environment;
1818

19-
class PreviewUnavailableTwigComponent implements ComponentInterface
19+
final readonly class PreviewUnavailableTwigComponent implements ComponentInterface
2020
{
21-
private Environment $twig;
22-
23-
/** @var \Ibexa\AdminUi\Siteaccess\NonAdminSiteaccessResolver */
24-
private SiteaccessResolverInterface $siteaccessResolver;
25-
26-
private LocationService $locationService;
27-
28-
/**
29-
* @param \Twig\Environment $twig
30-
* @param \Ibexa\AdminUi\Siteaccess\NonAdminSiteaccessResolver $siteaccessResolver
31-
* @param \Ibexa\Contracts\Core\Repository\LocationService $locationService
32-
*/
3321
public function __construct(
34-
Environment $twig,
35-
SiteaccessResolverInterface $siteaccessResolver,
36-
LocationService $locationService
22+
private Environment $twig,
23+
private SiteaccessResolverInterface $siteaccessResolver,
24+
private LocationService $locationService
3725
) {
38-
$this->twig = $twig;
39-
$this->siteaccessResolver = $siteaccessResolver;
40-
$this->locationService = $locationService;
4126
}
4227

4328
/**
44-
* @param array $parameters
45-
*
46-
* @return string
29+
* @param array<mixed> $parameters
4730
*/
4831
public function render(array $parameters = []): string
4932
{
@@ -56,9 +39,17 @@ public function render(array $parameters = []): string
5639
$versionNo = $content->getVersionInfo()->versionNo;
5740

5841
// nonpublished content should use parent location instead because location doesn't exist yet
59-
if (!$content->contentInfo->published && null === $content->contentInfo->mainLocationId) {
60-
$parentLocations = $this->locationService->loadParentLocationsForDraftContent($content->getVersionInfo());
42+
$contentInfo = $content->getContentInfo();
43+
if (!$contentInfo->isPublished() && null === $contentInfo->getMainLocationId()) {
44+
$parentLocations = $this->locationService->loadParentLocationsForDraftContent(
45+
$content->getVersionInfo()
46+
);
47+
6148
$location = reset($parentLocations);
49+
if ($location === false) {
50+
return '';
51+
}
52+
6253
$versionNo = null;
6354
}
6455

@@ -68,7 +59,7 @@ public function render(array $parameters = []): string
6859
$versionNo,
6960
$language->languageCode
7061
);
71-
} catch (UnauthorizedException $e) {
62+
} catch (UnauthorizedException) {
7263
$siteaccesses = [];
7364
}
7465

src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,14 @@
1212
use Ibexa\Contracts\TwigComponents\ComponentInterface;
1313
use Twig\Environment;
1414

15-
final class ContentTypeEditMetaFieldsComponent implements ComponentInterface
15+
final readonly class ContentTypeEditMetaFieldsComponent implements ComponentInterface
1616
{
17-
private const NO_CONTENT = '';
18-
19-
private ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver;
20-
21-
private Environment $twig;
17+
private const string NO_CONTENT = '';
2218

2319
public function __construct(
24-
ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver,
25-
Environment $twig
20+
private ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver,
21+
private Environment $twig
2622
) {
27-
$this->contentTypeFieldTypesResolver = $contentTypeFieldTypesResolver;
28-
$this->twig = $twig;
2923
}
3024

3125
/**

src/lib/Component/Event/RenderGroupEvent.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,43 @@
1515
* @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Event\RenderGroupEvent} class is deprecated, will be removed in 6.0.
1616
* Use {@see \Ibexa\Contracts\TwigComponents\Event\RenderGroupEvent} instead
1717
*/
18-
class RenderGroupEvent extends Event
18+
final class RenderGroupEvent extends Event
1919
{
20-
public const NAME = 'ezplatform_admin_ui.component.render_group';
21-
22-
private Registry $registry;
23-
24-
private string $groupName;
25-
26-
private array $parameters;
20+
public const string NAME = 'ezplatform_admin_ui.component.render_group';
2721

2822
/**
29-
* @param \Ibexa\AdminUi\Component\Registry $registry
30-
* @param string $groupName
31-
* @param array $parameters
23+
* @param array<string, mixed> $parameters
3224
*/
33-
public function __construct(Registry $registry, string $groupName, array $parameters = [])
34-
{
35-
$this->registry = $registry;
36-
$this->groupName = $groupName;
37-
$this->parameters = $parameters;
25+
public function __construct(
26+
private readonly Registry $registry,
27+
private readonly string $groupName,
28+
private readonly array $parameters = []
29+
) {
3830
}
3931

40-
/**
41-
* @return string
42-
*/
4332
public function getGroupName(): string
4433
{
4534
return $this->groupName;
4635
}
4736

4837
/**
49-
* @return array
38+
* @return \Ibexa\Contracts\TwigComponents\ComponentInterface[]
5039
*/
5140
public function getComponents(): array
5241
{
5342
return $this->registry->getComponents($this->getGroupName());
5443
}
5544

5645
/**
57-
* @param array $components
46+
* @param \Ibexa\Contracts\TwigComponents\ComponentInterface[] $components
5847
*/
5948
public function setComponents(array $components): void
6049
{
6150
$this->registry->setComponents($this->getGroupName(), $components);
6251
}
6352

6453
/**
65-
* @return array
54+
* @return array<string, mixed>
6655
*/
6756
public function getParameters(): array
6857
{

src/lib/Component/Event/RenderSingleEvent.php

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,38 @@
1616
* @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Event\RenderSingleEvent} class is deprecated, will be removed in 6.0.
1717
* Use {@see \Ibexa\Contracts\TwigComponents\Event\RenderSingleEvent} instead
1818
*/
19-
class RenderSingleEvent extends Event
19+
final class RenderSingleEvent extends Event
2020
{
21-
public const NAME = 'ezplatform_admin_ui.component.render_single';
22-
23-
private Registry $registry;
24-
25-
private string $groupName;
26-
27-
private string $serviceId;
28-
29-
private array $parameters;
21+
public const string NAME = 'ezplatform_admin_ui.component.render_single';
3022

3123
/**
32-
* @param \Ibexa\AdminUi\Component\Registry $registry
33-
* @param string $groupName
34-
* @param array $parameters
24+
* @param array<string, mixed> $parameters
3525
*/
36-
public function __construct(Registry $registry, string $groupName, string $serviceId, array $parameters = [])
37-
{
38-
$this->registry = $registry;
39-
$this->groupName = $groupName;
40-
$this->serviceId = $serviceId;
41-
$this->parameters = $parameters;
26+
public function __construct(
27+
private readonly Registry $registry,
28+
private readonly string $groupName,
29+
private readonly string $serviceId,
30+
private readonly array $parameters = []
31+
) {
4232
}
4333

44-
/**
45-
* @return string
46-
*/
4734
public function getGroupName(): string
4835
{
4936
return $this->groupName;
5037
}
5138

52-
/**
53-
* @return string
54-
*/
5539
public function getName(): string
5640
{
5741
return $this->serviceId;
5842
}
5943

60-
/**
61-
* @return \Ibexa\Contracts\TwigComponents\ComponentInterface
62-
*/
6344
public function getComponent(): ComponentInterface
6445
{
6546
$group = $this->registry->getComponents($this->getGroupName());
6647

6748
return $group[$this->serviceId];
6849
}
6950

70-
/**
71-
* @param \Ibexa\Contracts\TwigComponents\ComponentInterface $component
72-
*/
7351
public function setComponent(ComponentInterface $component): void
7452
{
7553
$this->registry->addComponent($this->getGroupName(), $this->getName(), $component);

src/lib/Component/EventSubscriber/RenderEventSubscriber.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818

19-
final class RenderEventSubscriber implements EventSubscriberInterface
19+
final readonly class RenderEventSubscriber implements EventSubscriberInterface
2020
{
21-
private Registry $registry;
22-
23-
private EventDispatcherInterface $eventDispatcher;
24-
2521
public function __construct(
26-
EventDispatcherInterface $eventDispatcher,
27-
Registry $registry
22+
private EventDispatcherInterface $eventDispatcher,
23+
private Registry $registry
2824
) {
29-
$this->registry = $registry;
30-
$this->eventDispatcher = $eventDispatcher;
3125
}
3226

3327
public static function getSubscribedEvents(): array

src/lib/Component/LinkComponent.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,20 @@
1515
* @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\LinkComponent} class is deprecated, will be removed in 6.0.
1616
* Use {@see \Ibexa\TwigComponents\Component\LinkComponent} instead
1717
*/
18-
class LinkComponent implements ComponentInterface
18+
readonly class LinkComponent implements ComponentInterface
1919
{
20-
protected Environment $twig;
21-
22-
protected string $href;
23-
24-
protected string $type;
25-
26-
protected string $rel;
27-
28-
protected ?string $crossorigin;
29-
30-
protected ?string $integrity;
31-
3220
public function __construct(
33-
Environment $twig,
34-
string $href,
35-
string $type = 'text/css',
36-
string $rel = 'stylesheet',
37-
?string $crossorigin = null,
38-
?string $integrity = null
21+
protected Environment $twig,
22+
protected string $href,
23+
protected string $type = 'text/css',
24+
protected string $rel = 'stylesheet',
25+
protected ?string $crossorigin = null,
26+
protected ?string $integrity = null
3927
) {
40-
$this->twig = $twig;
41-
$this->href = $href;
42-
$this->type = $type;
43-
$this->rel = $rel;
44-
$this->crossorigin = $crossorigin;
45-
$this->integrity = $integrity;
4628
}
4729

4830
/**
49-
* @param array $parameters
50-
*
51-
* @return string
31+
* @param array<mixed> $parameters
5232
*/
5333
public function render(array $parameters = []): string
5434
{

0 commit comments

Comments
 (0)