Skip to content

Commit 44a9e3e

Browse files
committed
CS Fixes
1 parent f48eec0 commit 44a9e3e

3 files changed

Lines changed: 51 additions & 53 deletions

File tree

src/Command/GenerateFixturesCommand.php

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
use Doctrine\Persistence\ManagerRegistry;
1515
use Silverback\ApiComponentsBundle\Entity\Core\AbstractPageData;
1616
use Silverback\ApiComponentsBundle\Entity\Core\ComponentGroup;
17-
use Silverback\ApiComponentsBundle\Entity\Core\Route;
1817
use Silverback\ApiComponentsBundle\Entity\Core\ComponentPosition;
1918
use Silverback\ApiComponentsBundle\Entity\Core\Layout;
2019
use Silverback\ApiComponentsBundle\Entity\Core\Page;
20+
use Silverback\ApiComponentsBundle\Entity\Core\Route;
2121
use Symfony\Component\Console\Command\Command;
2222
use Symfony\Component\Console\Input\InputInterface;
2323
use Symfony\Component\Console\Input\InputOption;
@@ -63,15 +63,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363
$childPagesByParent = [];
6464
foreach ($pages as $page) {
6565
$parent = $page->getParentPageData() ?? $page->getParentPage();
66-
if ($parent !== null) {
66+
if (null !== $parent) {
6767
$childPagesByParent[spl_object_id($parent)][] = $page;
6868
}
6969
}
7070

7171
$childPageDataByParent = [];
7272
foreach ($allPageData as $pd) {
7373
$parent = $pd->getParentPageData() ?? $pd->getParentPage();
74-
if ($parent !== null) {
74+
if (null !== $parent) {
7575
$childPageDataByParent[spl_object_id($parent)][] = $pd;
7676
}
7777
}
@@ -83,22 +83,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
}
8484

8585
foreach ($pages as $page) {
86-
if ($page->getParentPage() !== null || $page->getParentPageData() !== null) {
86+
if (null !== $page->getParentPage() || null !== $page->getParentPageData()) {
8787
continue;
8888
}
8989
$body .= $this->emitPage($page, $childPagesByParent, $childPageDataByParent);
9090
}
9191

9292
foreach ($allPageData as $pd) {
93-
if ($pd->getParentPage() !== null || $pd->getParentPageData() !== null) {
93+
if (null !== $pd->getParentPage() || null !== $pd->getParentPageData()) {
9494
continue;
9595
}
9696
$body .= $this->emitPageData($pd, $childPagesByParent, $childPageDataByParent);
9797
}
9898

9999
file_put_contents($outputPath, $this->buildFile($body));
100100

101-
$output->writeln(sprintf('<info>Fixture class written to %s</info>', $outputPath));
101+
$output->writeln(\sprintf('<info>Fixture class written to %s</info>', $outputPath));
102102

103103
return Command::SUCCESS;
104104
}
@@ -110,7 +110,7 @@ private function emitLayout(Layout $layout): string
110110
$ui = var_export($layout->uiComponent, true);
111111

112112
$extra = '';
113-
if ($layout->uiClassNames !== null) {
113+
if (null !== $layout->uiClassNames) {
114114
$extra .= ', uiClassNames: ' . $this->exportArray($layout->uiClassNames);
115115
}
116116

@@ -133,15 +133,15 @@ private function emitGroupCall(ComponentGroup $group, string $ownerVar, string $
133133

134134
$positions = $group->componentPositions;
135135
if ($positions->isEmpty()) {
136-
return sprintf("%s%s->group(%s%s);\n", $indent, $ownerVar, var_export($groupName, true), $extra);
136+
return \sprintf("%s%s->group(%s%s);\n", $indent, $ownerVar, var_export($groupName, true), $extra);
137137
}
138138

139139
$posCode = '';
140140
foreach ($positions as $position) {
141141
$posCode .= $this->emitPosition($position, $indent . ' ');
142142
}
143143

144-
return sprintf(
144+
return \sprintf(
145145
"%s%s->group(%s%s, function (GroupBuilder \$g): void {\n%s%s});\n",
146146
$indent,
147147
$ownerVar,
@@ -154,8 +154,8 @@ private function emitGroupCall(ComponentGroup $group, string $ownerVar, string $
154154

155155
private function emitPosition(ComponentPosition $position, string $indent): string
156156
{
157-
if ($position->pageDataProperty !== null) {
158-
return sprintf(
157+
if (null !== $position->pageDataProperty) {
158+
return \sprintf(
159159
"%s\$g->pageDataPosition(%s, %s);\n",
160160
$indent,
161161
var_export($position->pageDataClass, true),
@@ -164,21 +164,21 @@ private function emitPosition(ComponentPosition $position, string $indent): stri
164164
}
165165

166166
$component = $position->component;
167-
if ($component === null) {
167+
if (null === $component) {
168168
return '';
169169
}
170170

171-
$fqcn = get_class($component);
171+
$fqcn = $component::class;
172172
$shortName = (new \ReflectionClass($component))->getShortName();
173173
$this->addUseClass($fqcn);
174174

175175
$varName = '$comp' . (++$this->compCounter);
176176
$code = "{$indent}{$varName} = new {$shortName}();\n";
177177

178-
if ($component->uiComponent !== null) {
178+
if (null !== $component->uiComponent) {
179179
$code .= "{$indent}{$varName}->uiComponent = " . var_export($component->uiComponent, true) . ";\n";
180180
}
181-
if ($component->uiClassNames !== null) {
181+
if (null !== $component->uiClassNames) {
182182
$code .= "{$indent}{$varName}->uiClassNames = " . $this->exportArray($component->uiClassNames) . ";\n";
183183
}
184184

@@ -188,7 +188,7 @@ private function emitPosition(ComponentPosition $position, string $indent): stri
188188
continue;
189189
}
190190
$value = $prop->getValue($component);
191-
if ($value === null) {
191+
if (null === $value) {
192192
continue;
193193
}
194194
$code .= "{$indent}{$varName}->{$prop->getName()} = " . var_export($value, true) . ";\n";
@@ -213,10 +213,10 @@ private function emitPage(
213213
$args = "{$ref}, {$ui}, layout: {$layoutRef}";
214214

215215
$route = $page->getRoute();
216-
if ($route !== null) {
216+
if (null !== $route) {
217217
$args .= ', route: ' . var_export($route->getPath(), true);
218218
$routeName = $this->getRouteName($route);
219-
if ($routeName !== null) {
219+
if (null !== $routeName) {
220220
$args .= ', routeName: ' . var_export($routeName, true);
221221
}
222222
}
@@ -225,7 +225,7 @@ private function emitPage(
225225
$args .= ', isTemplate: true';
226226
}
227227

228-
if ($page->uiClassNames !== null) {
228+
if (null !== $page->uiClassNames) {
229229
$args .= ', uiClassNames: ' . $this->exportArray($page->uiClassNames);
230230
}
231231

@@ -235,12 +235,12 @@ private function emitPage(
235235
$hasChildren = !empty($childPages) || !empty($childPd);
236236
$title = $page->getTitle();
237237

238-
if ($groups->isEmpty() && !$hasChildren && $title === null) {
238+
if ($groups->isEmpty() && !$hasChildren && null === $title) {
239239
return "{$indent}{$builderVar}->page({$args});\n";
240240
}
241241

242242
$configureLines = '';
243-
if ($title !== null) {
243+
if (null !== $title) {
244244
$configureLines .= "{$indent} \$page->title(" . var_export($title, true) . ");\n";
245245
}
246246
foreach ($groups as $group) {
@@ -258,11 +258,11 @@ private function emitPage(
258258
}
259259

260260
return <<<CODE
261-
{$indent}{$builderVar}->page({$args},
262-
{$indent} configure: function (PageBuilder \$page) use (\$cwa): void {
263-
{$configureLines}{$indent} }
264-
{$indent});
265-
CODE . "\n";
261+
{$indent}{$builderVar}->page({$args},
262+
{$indent} configure: function (PageBuilder \$page) use (\$cwa): void {
263+
{$configureLines}{$indent} }
264+
{$indent});
265+
CODE . "\n";
266266
}
267267

268268
private function emitPageData(
@@ -272,15 +272,15 @@ private function emitPageData(
272272
string $indent = ' ',
273273
string $builderVar = '$cwa',
274274
): string {
275-
$fqcn = get_class($pd);
275+
$fqcn = $pd::class;
276276
$shortName = (new \ReflectionClass($pd))->getShortName();
277277
$this->addUseClass($fqcn);
278278

279279
$varName = '$pd_' . $this->toVar($pd->getTitle() ?? 'pageData');
280280
$code = "{$indent}{$varName} = new {$shortName}();\n";
281281

282282
$title = $pd->getTitle();
283-
if ($title !== null) {
283+
if (null !== $title) {
284284
$code .= "{$indent}{$varName}->setTitle(" . var_export($title, true) . ");\n";
285285
}
286286

@@ -293,7 +293,7 @@ private function emitPageData(
293293
continue;
294294
}
295295
$value = $prop->getValue($pd);
296-
if ($value === null) {
296+
if (null === $value) {
297297
continue;
298298
}
299299
$code .= "{$indent}{$varName}->{$prop->getName()} = " . var_export($value, true) . ";\n";
@@ -307,13 +307,13 @@ private function emitPageData(
307307
$route = $pd->getRoute();
308308

309309
$pdArgs = $varName;
310-
if ($templateRef !== null) {
310+
if (null !== $templateRef) {
311311
$pdArgs .= ', template: ' . var_export($templateRef, true);
312312
}
313-
if ($route !== null) {
313+
if (null !== $route) {
314314
$pdArgs .= ', route: ' . var_export($route->getPath(), true);
315315
$routeName = $this->getRouteName($route);
316-
if ($routeName !== null) {
316+
if (null !== $routeName) {
317317
$pdArgs .= ', routeName: ' . var_export($routeName, true);
318318
}
319319
}
@@ -351,23 +351,23 @@ private function buildFile(string $body): string
351351
$extraUses = '';
352352
if (!empty($this->useClasses)) {
353353
sort($this->useClasses);
354-
$extraUses = "\n" . implode("\n", array_map(fn ($c) => "use {$c};", $this->useClasses));
354+
$extraUses = "\n" . implode("\n", array_map(static fn ($c) => "use {$c};", $this->useClasses));
355355
}
356356

357357
return <<<PHP
358-
<?php
358+
<?php
359359
360-
namespace App\\DataFixtures;
360+
namespace App\\DataFixtures;
361361
362-
{$coreUses}{$extraUses}
362+
{$coreUses}{$extraUses}
363363
364-
class GeneratedScaffold extends AbstractCwaScaffold
365-
{
366-
public function build(CwaFixtureBuilder \$cwa): void
367-
{
368-
{$body} }
369-
}
370-
PHP;
364+
class GeneratedScaffold extends AbstractCwaScaffold
365+
{
366+
public function build(CwaFixtureBuilder \$cwa): void
367+
{
368+
{$body} }
369+
}
370+
PHP;
371371
}
372372

373373
private function addUseClass(string $fqcn): void
@@ -381,7 +381,7 @@ private function extractGroupName(ComponentGroup $group): string
381381
{
382382
$reference = $group->reference ?? '';
383383
$location = $group->location ?? '';
384-
if ($location !== '' && str_contains($reference, '_' . $location)) {
384+
if ('' !== $location && str_contains($reference, '_' . $location)) {
385385
$name = substr($reference, 0, strpos($reference, '_' . $location));
386386
if (false !== $name && '' !== $name) {
387387
return $name;
@@ -398,7 +398,7 @@ private function toVar(string $str): string
398398

399399
private function exportArray(array $arr): string
400400
{
401-
$items = implode(', ', array_map(fn ($v) => var_export($v, true), $arr));
401+
$items = implode(', ', array_map(static fn ($v) => var_export($v, true), $arr));
402402

403403
return '[' . $items . ']';
404404
}

src/Maker/MakeRenameComponent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,27 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
123123
$groups = $this->registry->getRepository(ComponentGroup::class)->findAll();
124124
$affected = array_filter(
125125
$groups,
126-
fn (ComponentGroup $g) => \in_array($oldIri, $g->allowedComponents ?? [], true)
126+
static fn (ComponentGroup $g) => \in_array($oldIri, $g->allowedComponents ?? [], true)
127127
);
128128

129129
if (\count($affected) > 0) {
130-
$io->warning(sprintf(
130+
$io->warning(\sprintf(
131131
'The following ComponentGroups have allowedComponents referencing "%s". ' .
132132
'The migration updates the DB automatically, but you must also update ' .
133133
'any front-end components referencing these groups:',
134134
$oldIri
135135
));
136136
$io->table(
137137
['Location (IRI)', 'Reference'],
138-
array_map(fn (ComponentGroup $g) => [$g->location, $g->reference], $affected)
138+
array_map(static fn (ComponentGroup $g) => [$g->location, $g->reference], $affected)
139139
);
140140
}
141141

142142
$io->text([
143143
'<fg=yellow>Front-end checklist after renaming:</>',
144144
'',
145-
sprintf(' 1. Rename your Vue/front-end component file from <comment>%s</comment> to <comment>%s</comment>', $oldName, $newName),
146-
sprintf(' 2. Update any imports or registrations referencing <comment>%s</comment>', $oldName),
145+
\sprintf(' 1. Rename your Vue/front-end component file from <comment>%s</comment> to <comment>%s</comment>', $oldName, $newName),
146+
\sprintf(' 2. Update any imports or registrations referencing <comment>%s</comment>', $oldName),
147147
' 3. Run: <comment>php bin/console doctrine:migrations:migrate</comment>',
148148
]);
149149
}

tests/Command/GenerateFixturesCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Silverback\ApiComponentsBundle\Tests\Command;
1313

14-
use Doctrine\Common\Collections\ArrayCollection;
1514
use Doctrine\Persistence\ManagerRegistry;
1615
use Doctrine\Persistence\ObjectRepository;
1716
use PHPUnit\Framework\TestCase;
@@ -24,7 +23,6 @@
2423
use Silverback\ApiComponentsBundle\Entity\Core\Page;
2524
use Silverback\ApiComponentsBundle\Entity\Core\Route;
2625
use Silverback\ApiComponentsBundle\Fixture\AbstractCwaScaffold;
27-
use Symfony\Component\Console\Input\ArrayInput;
2826
use Symfony\Component\Console\Tester\CommandTester;
2927

3028
/**
@@ -107,7 +105,7 @@ private function runCommand(ManagerRegistry $registry, string $outputFile): int
107105
return $tester->execute(['--output' => $outputFile]);
108106
}
109107

110-
private function makeRoute(string $path, string $name = null): Route
108+
private function makeRoute(string $path, ?string $name = null): Route
111109
{
112110
$route = new Route();
113111
$route->setPath($path);

0 commit comments

Comments
 (0)