Skip to content

Commit 0239634

Browse files
minor symfony#53119 Code updates (javiereguiluz)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- Code updates | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT For your consideration, this PR includes several simplifications/improvements to code as suggested by PHPStorm inspection tools. Commits ------- e290334 Code updates
2 parents 053f2fd + e290334 commit 0239634

File tree

28 files changed

+45
-95
lines changed

28 files changed

+45
-95
lines changed

.github/get-modified-packages.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,15 @@
1919

2020
function getPackageType(string $packageDir): string
2121
{
22-
if (preg_match('@Symfony/Bridge/@', $packageDir)) {
23-
return 'bridge';
24-
}
25-
26-
if (preg_match('@Symfony/Bundle/@', $packageDir)) {
27-
return 'bundle';
28-
}
29-
30-
if (preg_match('@Symfony/Component/[^/]+/Bridge/@', $packageDir)) {
31-
return 'component_bridge';
32-
}
33-
34-
if (preg_match('@Symfony/Component/@', $packageDir)) {
35-
return 'component';
36-
}
37-
38-
if (preg_match('@Symfony/Contracts/@', $packageDir)) {
39-
return 'contract';
40-
}
41-
42-
if (preg_match('@Symfony/Contracts$@', $packageDir)) {
43-
return 'contracts';
44-
}
45-
46-
throw new \LogicException();
22+
return match (true) {
23+
str_contains($packageDir, 'Symfony/Bridge/') => 'bridge',
24+
str_contains($packageDir, 'Symfony/Bundle/') => 'bundle',
25+
preg_match('@Symfony/Component/[^/]+/Bridge/@', $packageDir) => 'component_bridge',
26+
str_contains($packageDir, 'Symfony/Component/') => 'component',
27+
str_contains($packageDir, 'Symfony/Contracts/') => 'contract',
28+
str_ends_with($packageDir, 'Symfony/Contracts') => 'contracts',
29+
default => throw new \LogicException(),
30+
};
4731
}
4832

4933
$newPackage = [];

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ private function sanitizeQuery(string $connectionName, array $query): array
163163
$query['types'][$j] = $type->getBindingType();
164164
try {
165165
$param = $type->convertToDatabaseValue($param, $this->registry->getConnection($connectionName)->getDatabasePlatform());
166-
} catch (\TypeError $e) {
167-
} catch (ConversionException $e) {
166+
} catch (\TypeError|ConversionException) {
168167
}
169168
}
170169
}

src/Symfony/Bridge/Twig/Command/DebugCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,7 @@ private function getFilesystemLoaders(): array
587587

588588
private function getFileLink(string $absolutePath): string
589589
{
590-
if (null === $this->fileLinkFormatter) {
591-
return '';
592-
}
593-
594-
return (string) $this->fileLinkFormatter->format($absolutePath, 1);
590+
return (string) $this->fileLinkFormatter?->format($absolutePath, 1);
595591
}
596592

597593
private function getAvailableFormatOptions(): array

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ private function getContainerAliasData(Alias $alias): array
323323
private function getEventDispatcherListenersData(EventDispatcherInterface $eventDispatcher, array $options): array
324324
{
325325
$data = [];
326-
$event = \array_key_exists('event', $options) ? $options['event'] : null;
326+
$event = $options['event'] ?? null;
327327

328328
if (null !== $event) {
329329
foreach ($eventDispatcher->getListeners($event) as $listener) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ private function getContainerParameterDocument(mixed $parameter, ?array $depreca
501501

502502
private function getEventDispatcherListenersDocument(EventDispatcherInterface $eventDispatcher, array $options): \DOMDocument
503503
{
504-
$event = \array_key_exists('event', $options) ? $options['event'] : null;
504+
$event = $options['event'] ?? null;
505505
$dom = new \DOMDocument('1.0', 'UTF-8');
506506
$dom->appendChild($eventDispatcherXML = $dom->createElement('event-dispatcher'));
507507

src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ public function getListeners(Request $request): array
4646

4747
public function getFirewallConfig(Request $request): ?FirewallConfig
4848
{
49-
$context = $this->getFirewallContext($request);
50-
51-
if (null === $context) {
52-
return null;
53-
}
54-
55-
return $context->getConfig();
49+
return $this->getFirewallContext($request)?->getConfig();
5650
}
5751

5852
private function getFirewallContext(Request $request): ?FirewallContext

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ private function fillNextRows(array $rows, int $line): array
717717

718718
foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
719719
// we need to know if $unmergedRow will be merged or inserted into $rows
720-
if (isset($rows[$unmergedRowKey]) && \is_array($rows[$unmergedRowKey]) && ($this->getNumberOfColumns($rows[$unmergedRowKey]) + $this->getNumberOfColumns($unmergedRows[$unmergedRowKey]) <= $this->numberOfColumns)) {
720+
if (isset($rows[$unmergedRowKey]) && \is_array($rows[$unmergedRowKey]) && ($this->getNumberOfColumns($rows[$unmergedRowKey]) + $this->getNumberOfColumns($unmergedRow) <= $this->numberOfColumns)) {
721721
foreach ($unmergedRow as $cellKey => $cell) {
722722
// insert cell into row at cellKey position
723723
array_splice($rows[$unmergedRowKey], $cellKey, 0, [$cell]);
@@ -726,7 +726,7 @@ private function fillNextRows(array $rows, int $line): array
726726
$row = $this->copyRow($rows, $unmergedRowKey - 1);
727727
foreach ($unmergedRow as $column => $cell) {
728728
if (!empty($cell)) {
729-
$row[$column] = $unmergedRow[$column];
729+
$row[$column] = $cell;
730730
}
731731
}
732732
array_splice($rows, $unmergedRowKey, 0, [$row]);

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private function resolveCommands(string $value, array $loadedVars): string
463463
throw $this->createFormatException(sprintf('Issue expanding a command (%s)', $process->getErrorOutput()));
464464
}
465465

466-
return preg_replace('/[\r\n]+$/', '', $process->getOutput());
466+
return rtrim($process->getOutput(), "\n\r");
467467
}, $value);
468468
}
469469

src/Symfony/Component/Filesystem/Path.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ public static function changeExtension(string $path, string $extension): string
346346
$extension = ltrim($extension, '.');
347347

348348
// No extension for paths
349-
if ('/' === substr($path, -1)) {
349+
if (str_ends_with($path, '/')) {
350350
return $path;
351351
}
352352

353353
// No actual extension in path
354354
if (empty($actualExtension)) {
355-
return $path.('.' === substr($path, -1) ? '' : '.').$extension;
355+
return $path.(str_ends_with($path, '.') ? '' : '.').$extension;
356356
}
357357

358358
return substr($path, 0, -\strlen($actualExtension)).$extension;

src/Symfony/Component/Form/Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function getOptionDefinition(OptionsResolver $optionsResolver, string
128128
}
129129
}
130130

131-
if (isset($definition['deprecation']) && isset($definition['deprecation']['message']) && \is_string($definition['deprecation']['message'])) {
131+
if (isset($definition['deprecation']['message']) && \is_string($definition['deprecation']['message'])) {
132132
$definition['deprecationMessage'] = strtr($definition['deprecation']['message'], ['%name%' => $option]);
133133
$definition['deprecationPackage'] = $definition['deprecation']['package'];
134134
$definition['deprecationVersion'] = $definition['deprecation']['version'];

0 commit comments

Comments
 (0)