Skip to content

Commit 6c82c9d

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Cache][Config][Console][DependencyInjection][FrameworkBundle] Remove dead code and useless casts
1 parent aa26b97 commit 6c82c9d

File tree

4 files changed

+11
-23
lines changed

4 files changed

+11
-23
lines changed

Compiler/AutowirePass.php

Lines changed: 1 addition & 2 deletions
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) {

Dumper/PhpDumper.php

Lines changed: 5 additions & 14 deletions
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;

Loader/UndefinedExtensionHandler.php

Lines changed: 1 addition & 3 deletions
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
}

Loader/XmlFileLoader.php

Lines changed: 4 additions & 4 deletions
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)