Skip to content

Remove unused code and unnecessary else branches #57897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function format(LogRecord $record): mixed
$extra = '';
}

$formatted = strtr($this->options['format'], [
return strtr($this->options['format'], [
'%datetime%' => $record->datetime->format($this->options['date_format']),
'%start_tag%' => \sprintf('<%s>', self::LEVEL_COLOR_MAP[$record->level->value]),
'%level_name%' => \sprintf($this->options['level_name_format'], $record->level->getName()),
Expand All @@ -124,8 +124,6 @@ public function format(LogRecord $record): mixed
'%context%' => $context,
'%extra%' => $extra,
]);

return $formatted;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ public function __construct(string $message, array $trace, string $file, bool $l
if (($test instanceof TestCase || $test instanceof TestSuite) && ('trigger_error' !== $trace[$i - 2]['function'] || isset($trace[$i - 2]['class']))) {
$this->originClass = \get_class($test);
$this->originMethod = $test->getName();

return;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bridge/PsrHttpMessage/Factory/PsrHttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ public function createResponse(Response $symfonyResponse): ResponseInterface
}

$protocolVersion = $symfonyResponse->getProtocolVersion();
$response = $response->withProtocolVersion($protocolVersion);

return $response;
return $response->withProtocolVersion($protocolVersion);
}
}
4 changes: 1 addition & 3 deletions src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,13 @@ private function getMetadata(string $type, mixed $entity): mixed
}

// format args
$args = array_map(function (\ReflectionParameter $param) {
return array_map(function (\ReflectionParameter $param) {
if ($param->isDefaultValueAvailable()) {
return $param->getName().' = '.json_encode($param->getDefaultValue());
}

return $param->getName();
}, $args);

return $args;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function enterNode(Node $node, Environment $env): Node
$this->scope->set('domain', $node->getNode('expr'));

return $node;
} else {
$name = new AssignNameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine());
$this->scope->set('domain', new NameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine()));

return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
}

$name = new AssignNameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine());
$this->scope->set('domain', new NameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine()));

return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
}

if (!$this->scope->has('domain')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ protected function instantiateController(string $class): object
if ($controller instanceof AbstractController) {
if (null === $previousContainer = $controller->setContainer($this->container)) {
throw new \LogicException(\sprintf('"%s" has no container set, did you forget to define it as a service subscriber?', $class));
} else {
$controller->setContainer($previousContainer);
}

$controller->setContainer($previousContainer);
}

return $controller;
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Config/Builder/ClassBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function build(): string
}
}

$content = strtr('<?php
return strtr('<?php

namespace NAMESPACE;

Expand All @@ -95,8 +95,6 @@ class CLASS IMPLEMENTS
BODY
}
', ['NAMESPACE' => $this->namespace, 'REQUIRE' => $require, 'USE' => $use, 'CLASS' => $this->getName(), 'IMPLEMENTS' => $implements, 'BODY' => $body]);

return $content;
}

public function addRequire(self $class): void
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti

if (CompletionInput::TYPE_OPTION_NAME === $input->getCompletionType()) {
$suggestions->suggestOptions($this->getDefinition()->getOptions());

return;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Helper/ProgressBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ private function buildLine(): string
{
\assert(null !== $this->format);

$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
$regex = '{%([a-z\-_]+)(?:\:([^%]+))?%}i';
$callback = function ($matches) {
if ($formatter = $this->getPlaceholderFormatter($matches[1])) {
$text = $formatter($this, $this->output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function display(): void
return;
}

$this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) {
$this->overwrite(preg_replace_callback('{%([a-z\-_]+)(?:\:([^%]+))?%}i', function ($matches) {
if ($formatter = self::getPlaceholderFormatterDefinition($matches[1])) {
return $formatter($this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Input/ArgvInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
protected function parse(): void
{
$parseOptions = true;
$this->parsed = $this->tokens;

Check failure on line 75 in src/Symfony/Component/Console/Input/ArgvInput.php

View workflow job for this annotation

GitHub Actions / Psalm

InaccessibleProperty

src/Symfony/Component/Console/Input/ArgvInput.php:75:25: InaccessibleProperty: Cannot access private property Symfony\Component\Console\Completion\CompletionInput::$tokens from context Symfony\Component\Console\Input\ArgvInput (see https://psalm.dev/054)
while (null !== $token = array_shift($this->parsed)) {
$parseOptions = $this->parseToken($token, $parseOptions);
}
Expand Down Expand Up @@ -133,9 +133,9 @@
$this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));

break;
} else {
$this->addLongOption($option->getName(), null);
}

$this->addLongOption($option->getName(), null);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Console/Output/AnsiColorMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ private function degradeHexColorToAnsi8(int $r, int $g, int $b): int
}

return (int) round(($r - 8) / 247 * 24) + 232;
} else {
return 16 +
(36 * (int) round($r / 255 * 5)) +
(6 * (int) round($g / 255 * 5)) +
(int) round($b / 255 * 5);
}

return 16 +
(36 * (int) round($r / 255 * 5)) +
(6 * (int) round($g / 255 * 5)) +
(int) round($b / 255 * 5);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1940,11 +1940,11 @@ private function dumpValue(mixed $value, bool $interpolate = true): string
// we do this to deal with non string values (Boolean, integer, ...)
// the preg_replace_callback converts them to strings
return $this->dumpParameter($match[1]);
} else {
$replaceParameters = fn ($match) => "'.".$this->dumpParameter($match[2]).".'";

return str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
}

$replaceParameters = fn($match) => "'." . $this->dumpParameter($match[2]) . ".'";

return str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
} elseif ($value instanceof \UnitEnum) {
return \sprintf('\%s::%s', $value::class, $value->name);
} elseif ($value instanceof AbstractArgument) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed

if ('file' === $prefix) {
return file_get_contents($file);
} else {
return require $file;
}

return require $file;
}

$returnNull = false;
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private function resolveVariables(string $value, array $loadedVars): string
(?P<closing_brace>\})? # optional closing brace
/x';

$value = preg_replace_callback($regex, function ($matches) use ($loadedVars) {
return preg_replace_callback($regex, function ($matches) use ($loadedVars) {
// odd number of backslashes means the $ character is escaped
if (1 === \strlen($matches['backslashes']) % 2) {
return substr($matches[0], 1);
Expand Down Expand Up @@ -532,8 +532,6 @@ private function resolveVariables(string $value, array $loadedVars): string

return $matches['backslashes'].$value;
}, $value);

return $value;
}

private function moveCursor(string $text): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ public function transform(mixed $dateInterval): array
}
}
$result['invert'] = '-' === $result['invert'];
$result = array_intersect_key($result, array_flip($this->fields));

return $result;
return array_intersect_key($result, array_flip($this->fields));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public function transform(mixed $value): string
}

// Convert non-breaking and narrow non-breaking spaces to normal ones
$value = str_replace(["\xc2\xa0", "\xe2\x80\xaf"], ' ', $value);

return $value;
return str_replace(["\xc2\xa0", "\xe2\x80\xaf"], ' ', $value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ private function round(int|float $number): int|float
\NumberFormatter::ROUND_HALFDOWN => round($number, 0, \PHP_ROUND_HALF_DOWN),
};

$number = 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;

return $number;
return 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$knownValues[$child->getName()] = $value;
unset($unknownValues[$value]);
continue;
} else {
$knownValues[$child->getName()] = null;
}

$knownValues[$child->getName()] = null;
}
} else {
foreach ($choiceList->getChoicesForValues($data) as $key => $choice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ private function generateSymbolNamePairs(ArrayAccessibleResourceBundle $rootBund
$symbolNamePairs = array_map(fn ($pair) => \array_slice(iterator_to_array($pair), 0, 2), iterator_to_array($rootBundle['Currencies']));

// Remove unwanted currencies
$symbolNamePairs = array_diff_key($symbolNamePairs, self::DENYLIST);

return $symbolNamePairs;
return array_diff_key($symbolNamePairs, self::DENYLIST);
}

private function generateCurrencyMeta(ArrayAccessibleResourceBundle $supplementalDataBundle): array
Expand All @@ -134,9 +132,7 @@ private function generateAlpha3ToNumericMapping(ArrayAccessibleResourceBundle $n
asort($alpha3ToNumericMapping);

// Filter unknown currencies (e.g. "AYM")
$alpha3ToNumericMapping = array_intersect_key($alpha3ToNumericMapping, array_flip($currencyCodes));

return $alpha3ToNumericMapping;
return array_intersect_key($alpha3ToNumericMapping, array_flip($currencyCodes));
}

private function generateNumericToAlpha3Mapping(array $alpha3ToNumericMapping): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,10 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
$localizedNames[$language] = $name;
}
}
$data = [
return [
'Names' => $names,
'LocalizedNames' => $localizedNames,
];

return $data;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
sort($this->zoneIds);
ksort($this->zoneToCountryMapping);

$data = [
return [
'Zones' => $this->zoneIds,
'ZoneToCountry' => $this->zoneToCountryMapping,
'CountryToZone' => self::generateCountryToZoneMapping($this->zoneToCountryMapping),
];

return $data;
}

private function generateZones(BundleEntryReaderInterface $reader, string $tempDir, string $locale): array
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ private function connect(): void

if (false === $connection = ldap_connect($this->config['connection_string'])) {
throw new LdapException('Invalid connection string: '.$this->config['connection_string']);
} else {
$this->connection = $connection;
}

$this->connection = $connection;

foreach ($this->config['options'] as $name => $value) {
if (!\in_array(ConnectionOptions::getOption($name), self::PRECONNECT_OPTIONS, true)) {
$this->setOption($name, $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function getRequest(SentMessage $message): SendEmailRequest
$request['FromEmailAddressIdentityArn'] = $header->getBodyAsString();
}
if ($header = $email->getHeaders()->get('X-SES-LIST-MANAGEMENT-OPTIONS')) {
if (preg_match("/^(contactListName=)*(?<ContactListName>[^;]+)(;\s?topicName=(?<TopicName>.+))?$/ix", $header->getBodyAsString(), $listManagementOptions)) {
if (preg_match('/^(contactListName=)*(?<ContactListName>[^;]+)(;\s?topicName=(?<TopicName>.+))?$/ix', $header->getBodyAsString(), $listManagementOptions)) {
$request['ListManagementOptions'] = array_filter($listManagementOptions, fn ($e) => \in_array($e, ['ContactListName', 'TopicName']), \ARRAY_FILTER_USE_KEY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function getRequest(SentMessage $message): SendEmailRequest
$request['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
}
if ($header = $message->getOriginalMessage()->getHeaders()->get('X-SES-LIST-MANAGEMENT-OPTIONS')) {
if (preg_match("/^(contactListName=)*(?<ContactListName>[^;]+)(;\s?topicName=(?<TopicName>.+))?$/ix", $header->getBodyAsString(), $listManagementOptions)) {
if (preg_match('/^(contactListName=)*(?<ContactListName>[^;]+)(;\s?topicName=(?<TopicName>.+))?$/ix', $header->getBodyAsString(), $listManagementOptions)) {
$request['ListManagementOptions'] = array_filter($listManagementOptions, fn ($e) => \in_array($e, ['ContactListName', 'TopicName']), \ARRAY_FILTER_USE_KEY);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private function getResponse(#[\SensitiveParameter] string $secret, string $chal
$kopad = substr($secret, 0, 64) ^ str_repeat(\chr(0x5C), 64);

$inner = pack('H32', md5($kipad.$challenge));
$digest = md5($kopad.$inner);

return $digest;
return md5($kopad.$inner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
$ids[] = $this->getMessageId($envelope);
}
$suggestions->suggestValues($ids);

return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
{
if ($input->mustSuggestArgumentValuesFor('transport')) {
$suggestions->suggestValues($this->transportNames);

return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class FlattenExceptionNormalizer implements DenormalizerInterface, Normali

public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
$normalized = [
return [
'message' => $object->getMessage(),
'code' => $object->getCode(),
'headers' => $object->getHeaders(),
Expand All @@ -41,8 +41,6 @@ public function normalize(mixed $object, ?string $format = null, array $context
'trace' => $object->getTrace(),
'trace_as_string' => $object->getTraceAsString(),
];

return $normalized;
}

public function getSupportedTypes(?string $format): array
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Mime/Header/ParameterizedHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ private function createParameter(string $name, string $value): string
}

return implode(";\r\n ", $paramLines);
} else {
return $name.$this->getEndOfParameterValue($valueLines[0], $encoded, true);
}

return $name . $this->getEndOfParameterValue($valueLines[0], $encoded, true);
}

/**
Expand Down
Loading
Loading