Skip to content

Remove always true/false occurrences #58600

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function upgradePassword(PasswordAuthenticatedUserInterface $user, string
}

$repository = $this->getRepository();
if ($user instanceof PasswordAuthenticatedUserInterface && $repository instanceof PasswordUpgraderInterface) {
if ($repository instanceof PasswordUpgraderInterface) {
$repository->upgradePassword($user, $newHashedPassword);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Bridge/Twig/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ private function findWrongBundleOverrides(): array
}

if ($notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata)) {
$alternatives = [];
foreach ($notFoundBundles as $notFoundBundle => $path) {
$alternatives[$path] = $this->findAlternatives($notFoundBundle, array_keys($this->bundlesMetadata));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function describeContainerService(object $service, array $options = []
$options['output']->table(
['Service ID', 'Class'],
[
[$options['id'] ?? '-', $service::class],
[$options['id'], $service::class],
]
);
}
Expand Down Expand Up @@ -333,7 +333,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
$tableRows[] = ['Autoconfigured', $definition->isAutoconfigured() ? 'yes' : 'no'];

if ($definition->getFile()) {
$tableRows[] = ['Required File', $definition->getFile() ?: '-'];
$tableRows[] = ['Required File', $definition->getFile()];
}

if ($factory = $definition->getFactory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ private function createCommandTester($application = null): CommandTester

$command = $application->find('lint:xliff');

if ($application) {
$command->setApplication($application);
}
$command->setApplication($application);

return new CommandTester($command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ private function createCommandTester($application = null): CommandTester

$command = $application->find('lint:yaml');

if ($application) {
$command->setApplication($application);
}
$command->setApplication($application);

return new CommandTester($command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public function process(ContainerBuilder $container): void

// get the actual custom remember me handler definition (passed to the decorator)
$realRememberMeHandler = $container->findDefinition((string) $definition->getArgument(0));
if (null === $realRememberMeHandler) {
throw new \LogicException(\sprintf('Invalid service definition for custom remember me handler; no service found with ID "%s".', (string) $definition->getArgument(0)));
}

foreach ($rememberMeHandlerTags as $rememberMeHandlerTag) {
// some custom handlers may be used on multiple firewalls in the same application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\SecuredPageBundle\Security\Core\User;

use Symfony\Bundle\SecurityBundle\Tests\Functional\UserWithoutEquatable;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -59,10 +58,6 @@ public function loadUserByIdentifier(string $identifier): UserInterface

public function refreshUser(UserInterface $user): UserInterface
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
}

$storedUser = $this->getUser($user->getUserIdentifier());
$class = $storedUser::class;

Expand Down
6 changes: 2 additions & 4 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,10 @@ public function clear(string $prefix = ''): bool
unset($this->deferred[$key]);
}
}
} else {
$this->deferred = [];
}

if ($this->pool instanceof AdapterInterface) {
return $this->pool->clear($prefix);
} else {
$this->deferred = [];
}

return $this->pool->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ private function write(string $file, string $data, ?int $expiresAt = null): bool

if ('\\' === \DIRECTORY_SEPARATOR) {
$success = copy($tmp, $file);
$unlink = true;
} else {
$success = rename($tmp, $file);
$unlink = !$success;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
\extension_loaded('relay') => Relay::class,
default => \Predis\Client::class,
},
1 < \count($hosts) && \extension_loaded('redis') => 1 < \count($hosts) ? \RedisArray::class : \Redis::class,
1 < \count($hosts) && \extension_loaded('redis') => \RedisArray::class,
\extension_loaded('redis') => \Redis::class,
\extension_loaded('relay') => Relay::class,
default => \Predis\Client::class,
Expand Down Expand Up @@ -614,7 +614,7 @@ private function pipeline(\Closure $generator, ?object $redis = null): \Generato
}
});
} elseif ($redis instanceof \RedisArray) {
$connections = $results = $ids = [];
$connections = $results = [];
foreach ($generator() as $command => $args) {
$id = 'eval' === $command ? $args[1][0] : $args[0];
if (!isset($connections[$h = $redis->_target($id)])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Config/Definition/ArrayNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function addChild(NodeInterface $node): void
protected function finalizeValue(mixed $value): mixed
{
if (false === $value) {
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: false.', $this->getPath()));
}

foreach ($this->children as $name => $child) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function addChild(NodeInterface $node): never
protected function finalizeValue(mixed $value): mixed
{
if (false === $value) {
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: false.', $this->getPath()));
}

foreach ($value as $k => $v) {
Expand Down Expand Up @@ -218,7 +218,7 @@ protected function normalizeValue(mixed $value): mixed
$valuePrototype->parent = $this;
$originalClosures = $this->prototype->normalizationClosures;
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
$valuePrototype->normalizationClosures = \is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
$valuePrototype->normalizationClosures = array_merge($originalClosures, $valuePrototypeClosures);
$this->valuePrototypes[$k] = $valuePrototype;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function testIterator()

$paths = iterator_to_array($resource);

$file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
$this->assertEquals([$file => $file], $paths);
$this->assertInstanceOf(\SplFileInfo::class, current($paths));
$this->assertSame($dir, $resource->getPrefix());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function process(ContainerBuilder $container): void
$aliases = str_replace('%', '%%', $class::getDefaultName() ?? '');
}

$aliases = explode('|', $aliases ?? '');
$aliases = explode('|', $aliases);
$commandName = array_shift($aliases);

if ($isHidden = '' === $commandName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
$this->running = false;
}

return $ret ?? 1;
return $ret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function resolveEnvPlaceholders(mixed $value, string|bool|null $format =
$value = $bag->resolveValue($value);

if (!$bag instanceof EnvPlaceholderParameterBag) {
return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
return parent::resolveEnvPlaceholders($value, true, $usedEnvs);
}

foreach ($bag->getEnvPlaceholders() as $env => $placeholders) {
Expand All @@ -207,6 +207,6 @@ public function resolveEnvPlaceholders(mixed $value, string|bool|null $format =
}
}

return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
return parent::resolveEnvPlaceholders($value, true, $usedEnvs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function fileExists(string $path, bool|string $trackContents = true): boo
if (!$exists) {
$this->addResource(new FileExistenceResource($path));

return $exists;
return false;
}

if (is_dir($path)) {
Expand All @@ -459,7 +459,7 @@ public function fileExists(string $path, bool|string $trackContents = true): boo
$this->addResource(new FileResource($path));
}

return $exists;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ private function parseDefinition(string $id, array|string|null $service, string
throw new InvalidArgumentException(\sprintf('Missing attribute "version" of the "deprecated" option in "%s".', $file));
}

$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
$alias->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message'] ?? '');
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ private function parseDefinition(string $id, array|string|null $service, string
throw new InvalidArgumentException(\sprintf('Missing attribute "version" of the "deprecated" option in "%s".', $file));
}

$definition->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
$definition->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message'] ?? '');
}

if (isset($service['factory'])) {
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Component/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,24 +699,20 @@ public function getIterator(): \Iterator
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
*
* @return $this
*
* @throws \InvalidArgumentException when the given argument is not iterable
*/
public function append(iterable $iterator): static
{
if ($iterator instanceof \IteratorAggregate) {
$this->iterators[] = $iterator->getIterator();
} elseif ($iterator instanceof \Iterator) {
$this->iterators[] = $iterator;
} elseif (is_iterable($iterator)) {
} else {
$it = new \ArrayIterator();
foreach ($iterator as $file) {
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
$it[$file->getPathname()] = $file;
}
$this->iterators[] = $it;
} else {
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
}

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function reverseTransform(mixed $value): ?\DateInterval
'P%sY%sM%sWT%sH%sM%sS',
empty($value['years']) ? '0' : $value['years'],
empty($value['months']) ? '0' : $value['months'],
empty($value['weeks']) ? '0' : $value['weeks'],
$value['weeks'],
empty($value['hours']) ? '0' : $value['hours'],
empty($value['minutes']) ? '0' : $value['minutes'],
empty($value['seconds']) ? '0' : $value['seconds']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,8 @@ public function configureOptions(OptionsResolver $resolver): void

$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
if (\is_array($choiceTranslationDomain)) {
$default = false;

return array_replace(
['year' => $default, 'month' => $default, 'day' => $default],
['year' => false, 'month' => false, 'day' => false],
$choiceTranslationDomain
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,8 @@ public function configureOptions(OptionsResolver $resolver): void

$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
if (\is_array($choiceTranslationDomain)) {
$default = false;

return array_replace(
['hour' => $default, 'minute' => $default, 'second' => $default],
['hour' => false, 'minute' => false, 'second' => false],
$choiceTranslationDomain
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ public function configureOptions(OptionsResolver $resolver): void

$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
if (\is_array($choiceTranslationDomain)) {
$default = false;

return array_replace(
['year' => $default, 'week' => $default],
['year' => false, 'week' => false],
$choiceTranslationDomain
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function validate(mixed $form, Constraint $formConstraint): void
// Validate the data against its own constraints
$validateDataGraph = $form->isRoot()
&& (\is_object($data) || \is_array($data))
&& (($groups && \is_array($groups)) || ($groups instanceof GroupSequence && $groups->groups))
&& (\is_array($groups) || ($groups instanceof GroupSequence && $groups->groups))
;

// Validate the data against the constraints defined in the form
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ public function getPreferredLanguage(?array $locales = null): ?string
return $preferredLanguages[0] ?? null;
}

$locales = array_map($this->formatLocale(...), $locales ?? []);
$locales = array_map($this->formatLocale(...), $locales);
if (!$preferredLanguages) {
return $locales[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private function getContainerDeprecationLogs(): array
$log['priorityName'] = 'DEBUG';
$log['channel'] = null;
$log['scream'] = false;
unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['trace'], $log['count']);
unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['count']);
$logs[] = $log;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public static function fromDsn(#[\SensitiveParameter] string $dsn, array $option
}

if (isset($params['host'])) {
$options['host'] = $params['host'] ?? $options['host'];
$options['host'] = $params['host'];
$options['port'] = $params['port'] ?? $options['port'];

$pathParts = explode('/', rtrim($params['path'] ?? '', '/'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function doSend(MessageInterface $message): SentMessage
$result = $response->getContent(false);

$sentMessage = new SentMessage($message, (string) $this);
$sentMessage->setMessageId($result ?? '');
$sentMessage->setMessageId($result);

return $sentMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function onSuccessfulLogin(LoginSuccessEvent $event): void
$user = $token->getUserIdentifier();
$previousUser = $previousToken->getUserIdentifier();

if ('' !== ($user ?? '') && $user === $previousUser && $token::class === $previousToken::class) {
if ('' !== $user && $user === $previousUser && $token::class === $previousToken::class) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testPluralize(string $singular, $plural)
public function testUninflected(string $word)
{
$this->assertSame(
\is_array($word) ? $word : [$word],
[$word],
(new SpanishInflector())->pluralize($word)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/UnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function splice(string $replacement, int $start = 0, ?int $length = null)
$str = clone $this;

$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length)) : $length;
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);

if (normalizer_is_normalized($str->string)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ private function createCommand($requireStrictFileNames = true, $application = nu

$command = $application->find('lint:xliff');

if ($application) {
$command->setApplication($application);
}
$command->setApplication($application);

return $command;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public function testPayloadIsPassedToCallback()
$constraint = new Callback(callback: $callback, payload: 'Hello world!');
$this->validator->validate($object, $constraint);
$this->assertEquals('Hello world!', $payloadCopy);
$payloadCopy = 'Replace me!';

$payloadCopy = 'Replace me!';
$constraint = new Callback([
Expand Down
Loading