Skip to content

Commit 24d7bc4

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Cache][Config][Console][DependencyInjection][FrameworkBundle] Remove dead code and useless casts
1 parent 42b86e4 commit 24d7bc4

File tree

16 files changed

+35
-52
lines changed

16 files changed

+35
-52
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function warmUp(string $cacheDir, ?string $buildDir = null): array
5858
*/
5959
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values): array
6060
{
61-
return (array) $phpArrayAdapter->warmUp($values);
61+
return $phpArrayAdapter->warmUp($values);
6262
}
6363

6464
/**

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function describeContainerService(object $service, array $options = []
6464

6565
protected function describeContainerServices(ContainerBuilder $container, array $options = []): void
6666
{
67-
$this->writeDocument($this->getContainerServicesDocument($container, $options['tag'] ?? null, isset($options['show_hidden']) && $options['show_hidden'], isset($options['show_arguments']) && $options['show_arguments'], $options['filter'] ?? null, $options['id'] ?? null));
67+
$this->writeDocument($this->getContainerServicesDocument($container, $options['tag'] ?? null, isset($options['show_hidden']) && $options['show_hidden'], isset($options['show_arguments']) && $options['show_arguments'], $options['filter'] ?? null));
6868
}
6969

7070
protected function describeContainerDefinition(Definition $definition, array $options = [], ?ContainerBuilder $container = null): void
@@ -288,7 +288,7 @@ private function getContainerServiceDocument(object $service, string $id, ?Conta
288288
return $dom;
289289
}
290290

291-
private function getContainerServicesDocument(ContainerBuilder $container, ?string $tag = null, bool $showHidden = false, bool $showArguments = false, ?callable $filter = null, ?string $id = null): \DOMDocument
291+
private function getContainerServicesDocument(ContainerBuilder $container, ?string $tag = null, bool $showHidden = false, bool $showArguments = false, ?callable $filter = null): \DOMDocument
292292
{
293293
$dom = new \DOMDocument('1.0', 'UTF-8');
294294
$dom->appendChild($containerXML = $dom->createElement('container'));

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public function load(array $configs, ContainerBuilder $container): void
498498
if (!$messengerEnabled) {
499499
throw new LogicException('Scheduler support cannot be enabled as the Messenger component is not '.(interface_exists(MessageBusInterface::class) ? 'enabled.' : 'installed. Try running "composer require symfony/messenger".'));
500500
}
501-
$this->registerSchedulerConfiguration($config['scheduler'], $container, $loader);
501+
$this->registerSchedulerConfiguration($container, $loader);
502502
} else {
503503
$container->removeDefinition('cache.scheduler');
504504
$container->removeDefinition('console.command.scheduler_debug');
@@ -570,7 +570,7 @@ public function load(array $configs, ContainerBuilder $container): void
570570
}
571571

572572
if ($this->readConfigEnabled('remote-event', $container, $config['remote-event'])) {
573-
$this->registerRemoteEventConfiguration($config['remote-event'], $container, $loader);
573+
$this->registerRemoteEventConfiguration($loader);
574574
}
575575

576576
if ($this->readConfigEnabled('html_sanitizer', $container, $config['html_sanitizer'])) {
@@ -2073,7 +2073,7 @@ private function registerSemaphoreConfiguration(array $config, ContainerBuilder
20732073
}
20742074
}
20752075

2076-
private function registerSchedulerConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
2076+
private function registerSchedulerConfiguration(ContainerBuilder $container, PhpFileLoader $loader): void
20772077
{
20782078
if (!class_exists(SchedulerTransportFactory::class)) {
20792079
throw new LogicException('Scheduler support cannot be enabled as the Scheduler component is not installed. Try running "composer require symfony/scheduler".');
@@ -2940,7 +2940,7 @@ private function registerWebhookConfiguration(array $config, ContainerBuilder $c
29402940
$controller->replaceArgument(1, new Reference($config['message_bus']));
29412941
}
29422942

2943-
private function registerRemoteEventConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
2943+
private function registerRemoteEventConfiguration(PhpFileLoader $loader): void
29442944
{
29452945
if (!class_exists(RemoteEvent::class)) {
29462946
throw new LogicException('RemoteEvent support cannot be enabled as the component is not installed. Try running "composer require symfony/remote-event".');

src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function commit(): bool
186186
$e = $this->doSave($values, $lifetime, $addTagData, $removeTagData);
187187
} catch (\Exception $e) {
188188
}
189-
if (true === $e || [] === $e) {
189+
if ([] === $e) {
190190
continue;
191191
}
192192
if (\is_array($e) || 1 === \count($values)) {
@@ -213,7 +213,7 @@ public function commit(): bool
213213
$e = $this->doSave($values, $lifetime, $addTagData, $removeTagData);
214214
} catch (\Exception $e) {
215215
}
216-
if (true === $e || [] === $e) {
216+
if ([] === $e) {
217217
continue;
218218
}
219219
$ok = false;

src/Symfony/Component/Config/Definition/Dumper/YamlReferenceDumper.php

-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ private function writeArray(array $array, int $depth, bool $asComment = false):
193193
} else {
194194
$val = $value;
195195
}
196-
$prefix = $asComment ? '# ' : '';
197196

198197
$prefix = $asComment ? '# ' : '';
199198

src/Symfony/Component/Config/Definition/PrototypedArrayNode.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ protected function normalizeValue(mixed $value): mixed
217217
$valuePrototype = current($this->valuePrototypes) ?: clone $children['value'];
218218
$valuePrototype->parent = $this;
219219
$originalClosures = $this->prototype->normalizationClosures;
220-
if (\is_array($originalClosures)) {
221-
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
222-
$valuePrototype->normalizationClosures = \is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
223-
}
220+
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
221+
$valuePrototype->normalizationClosures = \is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
224222
$this->valuePrototypes[$k] = $valuePrototype;
225223
}
226224
}

src/Symfony/Component/Config/Util/XmlUtils.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function parse(string $content, string|callable|null $schemaOrCall
8080
$valid = false;
8181
}
8282
} elseif (is_file($schemaOrCallable)) {
83-
$schemaSource = (new Filesystem())->readFile((string) $schemaOrCallable);
83+
$schemaSource = (new Filesystem())->readFile($schemaOrCallable);
8484
$valid = @$dom->schemaValidateSource($schemaSource);
8585
} else {
8686
libxml_use_internal_errors($internalErrors);
@@ -156,7 +156,7 @@ public static function loadFile(string $file, string|callable|null $schemaOrCall
156156
*/
157157
public static function convertDomElementToArray(\DOMElement $element, bool $checkPrefix = true): mixed
158158
{
159-
$prefix = (string) $element->prefix;
159+
$prefix = $element->prefix;
160160
$empty = true;
161161
$config = [];
162162
foreach ($element->attributes as $name => $node) {
@@ -174,7 +174,7 @@ public static function convertDomElementToArray(\DOMElement $element, bool $chec
174174
$nodeValue = trim($node->nodeValue);
175175
$empty = false;
176176
}
177-
} elseif ($checkPrefix && $prefix != (string) $node->prefix) {
177+
} elseif ($checkPrefix && $prefix != $node->prefix) {
178178
continue;
179179
} elseif (!$node instanceof \DOMComment) {
180180
$value = static::convertDomElementToArray($node, $checkPrefix);

src/Symfony/Component/Console/Command/CompleteCommand.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9898
'',
9999
'<comment>'.date('Y-m-d H:i:s').'</>',
100100
'<info>Input:</> <comment>("|" indicates the cursor position)</>',
101-
' '.(string) $completionInput,
101+
' '.$completionInput,
102102
'<info>Command:</>',
103-
' '.(string) implode(' ', $_SERVER['argv']),
103+
' '.implode(' ', $_SERVER['argv']),
104104
'<info>Messages:</>',
105105
]);
106106

107-
$command = $this->findCommand($completionInput, $output);
107+
$command = $this->findCommand($completionInput);
108108
if (null === $command) {
109109
$this->log(' No command found, completing using the Application class.');
110110

@@ -185,7 +185,7 @@ private function createCompletionInput(InputInterface $input): CompletionInput
185185
return $completionInput;
186186
}
187187

188-
private function findCommand(CompletionInput $completionInput, OutputInterface $output): ?Command
188+
private function findCommand(CompletionInput $completionInput): ?Command
189189
{
190190
try {
191191
$inputName = $completionInput->getFirstArgument();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function describeInputOption(InputOption $option, array $options = [])
9292
protected function describeInputDefinition(InputDefinition $definition, array $options = []): void
9393
{
9494
if ($showArguments = ((bool) $definition->getArguments())) {
95-
$this->write("Arguments\n".str_repeat($this->subsubsectionChar, 9))."\n\n";
95+
$this->write("Arguments\n".str_repeat($this->subsubsectionChar, 9));
9696
foreach ($definition->getArguments() as $argument) {
9797
$this->write("\n\n");
9898
$this->describeInputArgument($argument);

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,9 @@ private function getInputOptionDocument(InputOption $option): \DOMDocument
208208
$defaults = \is_array($option->getDefault()) ? $option->getDefault() : (\is_bool($option->getDefault()) ? [var_export($option->getDefault(), true)] : ($option->getDefault() ? [$option->getDefault()] : []));
209209
$objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
210210

211-
if ($defaults) {
212-
foreach ($defaults as $default) {
213-
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
214-
$defaultXML->appendChild($dom->createTextNode($default));
215-
}
211+
foreach ($defaults as $default) {
212+
$defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
213+
$defaultXML->appendChild($dom->createTextNode($default));
216214
}
217215
}
218216

src/Symfony/Component/Console/Output/AnsiColorMode.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function convertFromHexToAnsiColorCode(string $hexColor): string
6262

6363
return match ($this) {
6464
self::Ansi4 => (string) $this->convertFromRGB($r, $g, $b),
65-
self::Ansi8 => '8;5;'.((string) $this->convertFromRGB($r, $g, $b)),
65+
self::Ansi8 => '8;5;'.$this->convertFromRGB($r, $g, $b),
6666
self::Ansi24 => \sprintf('8;2;%d;%d;%d', $r, $g, $b),
6767
};
6868
}

src/Symfony/Component/Console/Output/TrimmedBufferOutput.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ protected function doWrite(string $message, bool $newline): void
5353
$this->buffer .= \PHP_EOL;
5454
}
5555

56-
$this->buffer = substr($this->buffer, 0 - $this->maxLength);
56+
$this->buffer = substr($this->buffer, -$this->maxLength);
5757
}
5858
}

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,8 @@ private function getAliasesSuggestionForType(ContainerBuilder $container, string
689689
for ($i = 0, --$len; $i < $len; ++$i) {
690690
$message .= \sprintf('%s "%s", ', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]);
691691
}
692-
$message .= \sprintf('or %s "%s".', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]);
693692

694-
return $message;
693+
return $message.\sprintf('or %s "%s".', class_exists($aliases[$i], false) ? 'class' : 'interface', $aliases[$i]);
695694
}
696695

697696
if ($aliases) {

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ private function addInlineReference(string $id, Definition $definition, string $
10201020
return $code;
10211021
}
10221022

1023-
$code .= \sprintf(<<<'EOTXT'
1023+
return $code.\sprintf(<<<'EOTXT'
10241024
10251025
if (isset($container->%s[%s])) {
10261026
return $container->%1$s[%2$s];
@@ -1031,8 +1031,6 @@ private function addInlineReference(string $id, Definition $definition, string $
10311031
$this->container->getDefinition($id)->isPublic() ? 'services' : 'privates',
10321032
$this->doExport($id)
10331033
);
1034-
1035-
return $code;
10361034
}
10371035

10381036
private function addInlineService(string $id, Definition $definition, ?Definition $inlineDef = null, bool $forConstructor = true): string
@@ -1670,7 +1668,7 @@ public function getParameterBag(): ParameterBagInterface
16701668
$getDynamicParameter = str_repeat(' ', 8).'throw new ParameterNotFoundException($name);';
16711669
}
16721670

1673-
$code .= <<<EOF
1671+
return $code.<<<EOF
16741672
16751673
private \$loadedDynamicParameters = {$loadedDynamicParameters};
16761674
private \$dynamicParameters = [];
@@ -1686,8 +1684,6 @@ protected function getDefaultParameters(): array
16861684
}
16871685
16881686
EOF;
1689-
1690-
return $code;
16911687
}
16921688

16931689
/**
@@ -1947,9 +1943,7 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
19471943
} else {
19481944
$replaceParameters = fn ($match) => "'.".$this->dumpParameter($match[2]).".'";
19491945

1950-
$code = str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
1951-
1952-
return $code;
1946+
return str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
19531947
}
19541948
} elseif ($value instanceof \UnitEnum) {
19551949
return \sprintf('\%s::%s', $value::class, $value->name);
@@ -2102,11 +2096,8 @@ private function getNextVariableName(): string
21022096
while (true) {
21032097
$name = '';
21042098
$i = $this->variableCount;
2105-
2106-
if ('' === $name) {
2107-
$name .= $firstChars[$i % $firstCharsLength];
2108-
$i = (int) ($i / $firstCharsLength);
2109-
}
2099+
$name .= $firstChars[$i % $firstCharsLength];
2100+
$i = (int) ($i / $firstCharsLength);
21102101

21112102
while ($i > 0) {
21122103
--$i;

src/Symfony/Component/DependencyInjection/Loader/UndefinedExtensionHandler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public static function getErrorMessage(string $extensionName, ?string $loadingFi
3939
default => \sprintf('There is no extension able to load the configuration for "%s". ', $extensionName),
4040
};
4141

42-
$message .= \sprintf('Looked for namespace "%s", found "%s".', $namespaceOrAlias, $foundExtensionNamespaces ? implode('", "', $foundExtensionNamespaces) : 'none');
43-
44-
return $message;
42+
return $message.\sprintf('Looked for namespace "%s", found "%s".', $namespaceOrAlias, $foundExtensionNamespaces ? implode('", "', $foundExtensionNamespaces) : 'none');
4543
}
4644
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
347347
foreach ($tags as $tag) {
348348
$tagNameComesFromAttribute = $tag->childElementCount || '' === $tag->nodeValue;
349349
if ('' === $tagName = $tagNameComesFromAttribute ? $tag->getAttribute('name') : $tag->nodeValue) {
350-
throw new InvalidArgumentException(\sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
350+
throw new InvalidArgumentException(\sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', $service->getAttribute('id'), $file));
351351
}
352352

353-
$parameters = $this->getTagAttributes($tag, \sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, (string) $service->getAttribute('id'), $file));
353+
$parameters = $this->getTagAttributes($tag, \sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, $service->getAttribute('id'), $file));
354354
foreach ($tag->attributes as $name => $node) {
355355
if ($tagNameComesFromAttribute && 'name' === $name) {
356356
continue;
@@ -401,7 +401,7 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
401401

402402
if ($callable = $this->getChildren($service, 'from-callable')) {
403403
if ($definition instanceof ChildDefinition) {
404-
throw new InvalidArgumentException(\sprintf('Attribute "parent" is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
404+
throw new InvalidArgumentException(\sprintf('Attribute "parent" is unsupported when using "<from-callable>" on service "%s".', $service->getAttribute('id')));
405405
}
406406

407407
foreach ([
@@ -414,7 +414,7 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
414414
'Tag "<call>"' => 'getMethodCalls',
415415
] as $key => $method) {
416416
if ($definition->$method()) {
417-
throw new InvalidArgumentException($key.\sprintf(' is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
417+
throw new InvalidArgumentException($key.\sprintf(' is unsupported when using "<from-callable>" on service "%s".', $service->getAttribute('id')));
418418
}
419419
}
420420

0 commit comments

Comments
 (0)