Skip to content

Commit 75d26fe

Browse files
committed
CS Fixes
1 parent ccf4c72 commit 75d26fe

7 files changed

Lines changed: 70 additions & 27 deletions

File tree

features/bootstrap/DoctrineContext.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ public function thereIsADummyTimestampedWithSerializationGroupsResource(): void
352352
/**
353353
* @Given /^there is a ComponentGroup in a Page$/
354354
*/
355-
public function thereIsAComponentGroupInAPage() {
355+
public function thereIsAComponentGroupInAPage()
356+
{
356357
$page = $this->thereIsAPage();
357358
$group = $this->thereIsAComponentGroupWithComponents(1);
358359
$page->addComponentGroup($group);
@@ -363,7 +364,8 @@ public function thereIsAComponentGroupInAPage() {
363364
/**
364365
* @Given /^there is a ComponentGroup in a Page and a Layout$/
365366
*/
366-
public function thereIsAComponentGroupInAPageAndALayout() {
367+
public function thereIsAComponentGroupInAPageAndALayout()
368+
{
367369
$page = $this->thereIsAPage();
368370
$layout = $this->thereIsALayout();
369371
$group = $this->thereIsAComponentGroupWithComponents(1);
@@ -557,6 +559,7 @@ public function thereIsALayout(string $reference = 'no-reference', ?string $crea
557559
$this->manager->persist($layout);
558560
$this->manager->flush();
559561
$this->restContext->resources['layout'] = $this->iriConverter->getIriFromResource($layout);
562+
560563
return $layout;
561564
}
562565

src/Command/CleanOrphanedCommand.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This file is part of the Silverback API Components Bundle Project
5+
*
6+
* (c) Daniel West <daniel@silverback.is>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
314
namespace Silverback\ApiComponentsBundle\Command;
415

516
use Doctrine\Persistence\ManagerRegistry;
@@ -32,31 +43,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3243
$count = 0;
3344
$componentGroupRepository = $this->registry->getRepository(ComponentGroup::class);
3445
$componentGroups = $componentGroupRepository->findAll();
35-
$groupsProgressBar = new ProgressBar($output, count($componentGroups));
46+
$groupsProgressBar = new ProgressBar($output, \count($componentGroups));
3647
$groupsProgressBar->start();
3748
foreach ($componentGroups as $componentGroup) {
3849
$groupsProgressBar->advance();
3950
if ($this->orphanedResourceHelper->checkAndRemoveOrphanedComponentGroup($componentGroup)) {
40-
$count++;
51+
++$count;
4152
}
4253
}
4354
$groupsProgressBar->finish();
4455
$output->writeln('');
4556

4657
$componentRepository = $this->registry->getRepository(AbstractComponent::class);
4758
$components = $componentRepository->findAll();
48-
$componentsProgressBar = new ProgressBar($output, count($componentGroups));
59+
$componentsProgressBar = new ProgressBar($output, \count($componentGroups));
4960
$componentsProgressBar->start();
5061
foreach ($components as $component) {
5162
$componentsProgressBar->advance();
5263
if ($this->orphanedResourceHelper->checkAndRemoveOrphanedComponent($component)) {
53-
$count++;
64+
++$count;
5465
}
5566
}
5667
$componentsProgressBar->finish();
5768
$output->writeln('');
5869

5970
$output->writeln(\sprintf('Removed <info>%d</info> orphaned components (excluding cascades)', $count));
71+
6072
return 0;
6173
}
6274
}

src/DataProvider/StateProvider/ComponentGroupStateProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use ApiPlatform\Metadata\Operation;
2020
use ApiPlatform\State\ProviderInterface;
2121
use Silverback\ApiComponentsBundle\Repository\Core\ComponentGroupRepository;
22-
use Silverback\ApiComponentsBundle\Repository\Core\RouteRepository;
2322

2423
/**
2524
* @author Daniel West <daniel@silverback.is>
@@ -28,8 +27,9 @@ class ComponentGroupStateProvider implements ProviderInterface
2827
{
2928
public function __construct(
3029
private ComponentGroupRepository $componentGroupRepository,
31-
private ProviderInterface $defaultProvider)
32-
{}
30+
private ProviderInterface $defaultProvider,
31+
) {
32+
}
3333

3434
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
3535
{

src/Entity/Core/ComponentGroup.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
/**
2828
* @author Daniel West <daniel@silverback.is>
29+
*
2930
* @internal
31+
*
3032
* @description This is an internal class because we will detect when it is orphaned from known locations and delete it automatically
3133
*/
3234
#[Silverback\Timestamped]

src/EventListener/Api/DeletedResourceEventListener.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
/**
2828
* @author Daniel West <daniel@silverback.is>
2929
*/
30-
readonly class DeletedResourceEventListener {
30+
readonly class DeletedResourceEventListener
31+
{
3132
public function __construct(
32-
private OrphanedResourceHelper $orphanedResourceHelper) {
33+
private OrphanedResourceHelper $orphanedResourceHelper,
34+
) {
3335
}
3436

3537
public function onPreWrite(ViewEvent $event): void
@@ -44,6 +46,7 @@ public function onPreWrite(ViewEvent $event): void
4446

4547
if ($data instanceof ComponentPosition) {
4648
$this->orphanedResourceHelper->handleRemovedComponentPosition($data);
49+
4750
return;
4851
}
4952

src/Helper/OrphanedResourceHelper.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
<?php
22

3+
/*
4+
* This file is part of the Silverback API Components Bundle Project
5+
*
6+
* (c) Daniel West <daniel@silverback.is>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
314
namespace Silverback\ApiComponentsBundle\Helper;
415

516
use Doctrine\Persistence\ManagerRegistry;
@@ -21,26 +32,31 @@
2132
public function __construct(
2233
private PageDataMetadataFactoryInterface $pageDataMetadataFactory,
2334
private ComponentUsageMetadataFactory $usageMetadataFactory,
24-
private ManagerRegistry $registry) {
35+
private ManagerRegistry $registry,
36+
) {
2537
}
2638

27-
public function handleRemovedComponentPosition(ComponentPosition $componentPosition): void {
39+
public function handleRemovedComponentPosition(ComponentPosition $componentPosition): void
40+
{
2841
$this->removeOrphanedComponentPosition($componentPosition);
2942
}
3043

31-
public function handleRemovedRootResource(AbstractComponent|Page|Layout $resource): void {
44+
public function handleRemovedRootResource(AbstractComponent|Page|Layout $resource): void
45+
{
3246
foreach ($resource->getComponentGroups() as $componentGroup) {
3347
$this->removeOrphanedComponentGroup($componentGroup, $resource);
3448
}
3549
}
3650

37-
public function handleRemovedComponentGroup(ComponentGroup $componentGroup): void {
51+
public function handleRemovedComponentGroup(ComponentGroup $componentGroup): void
52+
{
3853
$this->removeOrphanedComponentGroup($componentGroup);
3954
}
4055

41-
public function handleRemovedPageData(PageDataInterface $resource, ?string $resourceClass): void {
56+
public function handleRemovedPageData(PageDataInterface $resource, ?string $resourceClass): void
57+
{
4258
$propertyAccessor = PropertyAccess::createPropertyAccessor();
43-
$pageDataMetadata = $this->pageDataMetadataFactory->create($resourceClass ?: get_class($resource));
59+
$pageDataMetadata = $this->pageDataMetadataFactory->create($resourceClass ?: $resource::class);
4460
foreach ($pageDataMetadata->getProperties() as $property) {
4561
$component = $propertyAccessor->getValue($resource, $property->getProperty());
4662
if ($component instanceof ComponentInterface) {
@@ -49,7 +65,8 @@ public function handleRemovedPageData(PageDataInterface $resource, ?string $reso
4965
}
5066
}
5167

52-
public function handleRemovedRoutable(RoutableInterface $resource): void {
68+
public function handleRemovedRoutable(RoutableInterface $resource): void
69+
{
5370
$route = $resource->getRoute();
5471
if ($route) {
5572
$routeAssociations = 0;
@@ -63,7 +80,8 @@ public function handleRemovedRoutable(RoutableInterface $resource): void {
6380
}
6481
}
6582

66-
public function checkAndRemoveOrphanedComponentGroup(ComponentGroup $componentGroup): bool {
83+
public function checkAndRemoveOrphanedComponentGroup(ComponentGroup $componentGroup): bool
84+
{
6785
if ($componentGroup->pages->count() || $componentGroup->layouts->count() || $componentGroup->components->count()) {
6886
return false;
6987
}
@@ -78,10 +96,12 @@ public function checkAndRemoveOrphanedComponentGroup(ComponentGroup $componentGr
7896
$groupManager?->remove($componentGroup);
7997
$groupManager?->flush();
8098
$positionManager?->flush();
99+
81100
return true;
82101
}
83102

84-
public function checkAndRemoveOrphanedComponent(AbstractComponent $component): bool {
103+
public function checkAndRemoveOrphanedComponent(AbstractComponent $component): bool
104+
{
85105
return $this->removeOrphanedComponent($component, 0, true);
86106
}
87107

@@ -105,10 +125,12 @@ private function isComponentGroupInOtherLocations(ComponentGroup $componentGroup
105125
return true;
106126
}
107127
}
128+
108129
return false;
109130
}
110131

111-
private function removeOrphanedComponentGroup(ComponentGroup $componentGroup, AbstractComponent|Page|Layout|null $deletedLocation = null): void {
132+
private function removeOrphanedComponentGroup(ComponentGroup $componentGroup, AbstractComponent|Page|Layout|null $deletedLocation = null): void
133+
{
112134
$groupExistsElsewhere = $this->isComponentGroupInOtherLocations($componentGroup, $deletedLocation);
113135
if ($groupExistsElsewhere) {
114136
return;
@@ -125,7 +147,8 @@ private function removeOrphanedComponentGroup(ComponentGroup $componentGroup, Ab
125147
}
126148
}
127149

128-
private function removeOrphanedComponentPosition(ComponentPosition $componentPosition): void {
150+
private function removeOrphanedComponentPosition(ComponentPosition $componentPosition): void
151+
{
129152
if ($componentPosition->component) {
130153
$this->removeOrphanedComponent($componentPosition->component);
131154
}
@@ -135,16 +158,16 @@ private function removeOrphanedComponent(ComponentInterface $component, int $cou
135158
{
136159
$metadata = $this->usageMetadataFactory->create($component);
137160
if ($countCheck === $metadata->getTotal()) {
138-
$resourceClass = get_class($component);
161+
$resourceClass = $component::class;
139162
$manager = $this->registry->getManagerForClass($resourceClass);
140163
$manager?->remove($component);
141164
if ($doFlush) {
142165
$manager?->flush();
143166
}
167+
144168
return true;
145169
}
170+
146171
return false;
147172
}
148-
149-
150173
}

src/Resources/config/services.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
use Silverback\ApiComponentsBundle\EventListener\Api\CollectionApiEventListener;
6666
use Silverback\ApiComponentsBundle\EventListener\Api\ComponentPositionEventListener;
6767
use Silverback\ApiComponentsBundle\EventListener\Api\ComponentUsageEventListener;
68-
use Silverback\ApiComponentsBundle\EventListener\Api\FormApiEventListener;
6968
use Silverback\ApiComponentsBundle\EventListener\Api\DeletedResourceEventListener;
69+
use Silverback\ApiComponentsBundle\EventListener\Api\FormApiEventListener;
7070
use Silverback\ApiComponentsBundle\EventListener\Api\PublishableEventListener;
7171
use Silverback\ApiComponentsBundle\EventListener\Api\RouteEventListener;
7272
use Silverback\ApiComponentsBundle\EventListener\Api\UploadableEventListener;
@@ -1157,7 +1157,7 @@
11571157
->args(
11581158
[
11591159
new Reference('silverback.helper.orphaned_resource_helper'),
1160-
new Reference(ManagerRegistry::class)
1160+
new Reference(ManagerRegistry::class),
11611161
]
11621162
);
11631163

0 commit comments

Comments
 (0)