8000 Remove always true/false occurrences · symfony/symfony@6980384 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6980384

Browse files
Remove always true/false occurrences
1 parent bc9f35c commit 6980384

File tree

34 files changed

+35
-65
lines changed

34 files changed

+35
-65
lines changed

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function upgradePassword(PasswordAuthenticatedUserInterface $user, string
121121
}
122122

123123
$repository = $this->getRepository();
124-
if ($user instanceof PasswordAuthenticatedUserInterface && $repository instanceof PasswordUpgraderInterface) {
124+
if ($repository instanceof PasswordUpgraderInterface) {
125125
$repository->upgradePassword($user, $newHashedPassword);
126126
}
127127
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ private function findWrongBundleOverrides(): array
412412
}
413413

414414
if ($notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata)) {
415-
$alternatives = [];
416415
foreach ($notFoundBundles as $notFoundBundle => $path) {
417416
$alternatives[$path] = $this->findAlternatives($notFoundBundle, array_keys($this->bundlesMetadata));
418417
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function describeContainerService(object $service, array $options = []
172172
$options['output']->table(
173173
['Service ID', 'Class'],
174174
[
175-
[$options['id'] ?? '-', $service::class],
175+
[$options['id'], $service::class],
176176
]
177177
);
178178
}
@@ -333,7 +333,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
333333
$tableRows[] = ['Autoconfigured', $definition->isAutoconfigured() ? 'yes' : 'no'];
334334

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

339339
if ($factory = $definition->getFactory()) {

src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ private function createCommandTester($application = null): CommandTester
6464

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

67-
if ($application) {
68-
$command->setApplication($application);
69-
}
67+
$command->setApplication($application);
7068

7169
return new CommandTester($command);
7270
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/YamlLintCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ private function createCommandTester($application = null): CommandTester
112112

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

115-
if ($application) {
116-
$command->setApplication($application);
117-
}
115+
$command->setApplication($application);
118116

119117
return new CommandTester($command);
120118
}

src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/ReplaceDecoratedRememberMeHandlerPass.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public function process(ContainerBuilder $container): void
3737

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

4441
foreach ($rememberMeHandlerTags as $rememberMeHandlerTag) {
4542
// some custom handlers may be used on multiple firewalls in the same application

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/SecuredPageBundle/Security/Core/User/ArrayUserProvider.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\SecuredPageBundle\Security\Core\User;
1313

1414
use Symfony\Bundle\SecurityBundle\Tests\Functional\UserWithoutEquatable;
15-
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1615
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
1716
use Symfony\Component\Security\Core\User\InMemoryUser;
1817
use Symfony\Component\Security\Core\User\UserInterface;
@@ -59,10 +58,6 @@ public function loadUserByIdentifier(string $identifier): UserInterface
5958

6059
public function refreshUser(UserInterface $user): UserInterface
6160
{
62-
if (!$user instanceof UserInterface) {
63-
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
64-
}
65-
6661
$storedUser = $this->getUser($user->getUserIdentifier());
6762
$class = $storedUser::class;
6863

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,10 @@ public function clear(string $prefix = ''): bool
207207
unset($this->deferred[$key]);
208208
}
209209
}
210-
} else {
211-
$this->deferred = [];
212-
}
213210

214-
if ($this->pool instanceof AdapterInterface) {
215211
return $this->pool->clear($prefix);
212+
} else {
213+
$this->deferred = [];
216214
}
217215

218216
return $this->pool->clear();

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ private function write(string $file, string $data, ?int $expiresAt = null): bool
108108

109109
if ('\\' === \DIRECTORY_SEPARATOR) {
110110
$success = copy($tmp, $file);
111-
$unlink = true;
112111
} else {
113112
$success = rename($tmp, $file);
114113
$unlink = !$success;

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
199199
\extension_loaded('relay') => Relay::class,
200200
default => \Predis\Client::class,
201201
},
202-
1 < \count($hosts) && \extension_loaded('redis') => 1 < \count($hosts) ? \RedisArray::class : \Redis::class,
202+
1 < \count($hosts) && \extension_loaded('redis') => \RedisArray::class,
203203
\extension_loaded('redis') => \Redis::class,
204204
\extension_loaded('relay') => Relay::class,
205205
default => \Predis\Client::class,
@@ -614,7 +614,7 @@ private function pipeline(\Closure $generator, ?object $redis = null): \Generato
614614
}
615615
});
616616
} elseif ($redis instanceof \RedisArray) {
617-
$connections = $results = $ids = [];
617+
$connections = $results = [];
618618
foreach ($generator() as $command => $args) {
619619
$id = 'eval' === $command ? $args[1][0] : $args[0];
620620
if (!isset($connections[$h = $redis->_target($id)])) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function addChild(NodeInterface $node): void
198198
protected function finalizeValue(mixed $value): mixed
199199
{
200200
if (false === $value) {
201-
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
201+
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: false.', $this->getPath()));
202202
}
203203

204204
foreach ($this->children as $name => $child) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function addChild(NodeInterface $node): never
156156
protected function finalizeValue(mixed $value): mixed
157157
{
158158
if (false === $value) {
159-
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: %s.', $this->getPath(), json_encode($value)));
159+
throw new UnsetKeyException(\sprintf('Unsetting key for path "%s", value: false.', $this->getPath()));
160160
}
161161

162162
foreach ($value as $k => $v) {
@@ -218,7 +218,7 @@ protected function normalizeValue(mixed $value): mixed
218218
$valuePrototype->parent = $this;
219219
$originalClosures = $this->prototype->normalizationClosures;
220220
$valuePrototypeClosures = $valuePrototype->normalizationClosures;
221-
$valuePrototype->normalizationClosures = \is_array($valuePrototypeClosures) ? array_merge($originalClosures, $valuePrototypeClosures) : $originalClosures;
221+
$valuePrototype->normalizationClosures = array_merge($originalClosures, $valuePrototypeClosures);
222222
$this->valuePrototypes[$k] = $valuePrototype;
223223
}
224224
}

src/Symfony/Component/Config/Tests/Res C2EE ource/GlobResourceTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function testIterator()
4141

4242
$paths = iterator_to_array($resource);
4343

44-
$file = $dir.'/Resource'.\DIRECTORY_SEPARATOR.'ConditionalClass.php';
4544
$this->assertEquals([$file => $file], $paths);
4645
$this->assertInstanceOf(\SplFileInfo::class, current($paths));
4746
$this->assertSame($dir, $resource->getPrefix());

src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function process(ContainerBuilder $container): void
5353
$aliases = str_replace('%', '%%', $class::getDefaultName() ?? '');
5454
}
5555

56-
$aliases = explode('|', $aliases ?? '');
56+
$aliases = explode('|', $aliases);
5757
$commandName = array_shift($aliases);
5858

5959
if ($isHidden = '' === $commandName) {

src/Symfony/Component/Console/SingleCommandApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
6767
$this->running = false;
6868
}
6969

70-
return $ret ?? 1;
70+
return $ret;
7171
}
7272
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function resolveEnvPlaceholders(mixed $value, string|bool|null $format =
193193
$value = $bag->resolveValue($value);
194194

195195
if (!$bag instanceof EnvPlaceholderParameterBag) {
196-
return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
196+
return parent::resolveEnvPlaceholders($value, true, $usedEnvs);
197197
}
198198

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

210-
return parent::resolveEnvPlaceholders($value, $format, $usedEnvs);
210+
return parent::resolveEnvPlaceholders($value, true, $usedEnvs);
211211
}
212212
}

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function fileExists(string $path, bool|string $trackContents = true): boo
446446
if (!$exists) {
447447
$this->addResource(new FileExistenceResource($path));
448448

449-
return $exists;
449+
return false;
450450
}
451451

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

462-
return $exists;
462+
return true;
463463
}
464464

465465
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ private function parseDefinition(string $id, array|string|null $service, string
448448
throw new InvalidArgumentException(\sprintf('Missing attribute "version" of the "deprecated" option in "%s".', $file));
449449
}
450450

451-
$alias->setDeprecated($deprecation['package'] ?? '', $deprecation['version'] ?? '', $deprecation['message'] ?? '');
451+
$alias->setDeprecated($deprecation['package'], $deprecation['version'], $deprecation['message'] ?? '');
452452
}
453453
}
454454

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

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

526526
if (isset($service['factory'])) {

src/Symfony/Component/Finder/Finder.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,24 +699,20 @@ public function getIterator(): \Iterator
699699
* The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
700700
*
701701
* @return $this
702-
*
703-
* @throws \InvalidArgumentException when the given argument is not iterable
704702
*/
705703
public function append(iterable $iterator): static
706704
{
707705
if ($iterator instanceof \IteratorAggregate) {
708706
$this->iterators[] = $iterator->getIterator();
709707
} elseif ($iterator instanceof \Iterator) {
710708
$this->iterators[] = $iterator;
711-
} elseif (is_iterable($iterator)) {
709+
} else {
712710
$it = new \ArrayIterator();
713711
foreach ($iterator as $file) {
714712
$file = $file instanceof \SplFileInfo ? $file : new \SplFileInfo($file);
715713
$it[$file->getPathname()] = $file;
716714
}
717715
$this->iterators[] = $it;
718-
} else {
719-
throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
720716
}
721717

722718
return $this;

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function reverseTransform(mixed $value): ?\DateInterval
139139
'P%sY%sM%sWT%sH%sM%sS',
140140
empty($value['years']) ? '0' : $value['years'],
141141
empty($value['months']) ? '0' : $value['months'],
142-
empty($value['weeks']) ? '0' : $value['weeks'],
142+
$value['weeks'],
143143
empty($value['hours']) ? '0' : $value['hours'],
144144
empty($value['minutes']) ? '0' : $value['minutes'],
145145
empty($value['seconds']) ? '0' : $value['seconds']

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ public function configureOptions(OptionsResolver $resolver): void
249249

250250
$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
251251
if (\is_array($choiceTranslationDomain)) {
252-
$default = false;
253-
254252
return array_replace(
255-
['year' => $default, 'month' => $default, 'day' => $default],
253+
['year' => false, 'month' => false, 'day' => false],
256254
$choiceTranslationDomain
257255
);
258256
}

src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,8 @@ public function configureOptions(OptionsResolver $resolver): void
274274

275275
$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
276276
if (\is_array($choiceTranslationDomain)) {
277-
$default = false;
278-
279277
return array_replace(
280-
['hour' => $default, 'minute' => $default, 'second' => $default],
278+
['hour' => false, 'minute' => false, 'second' => false],
281279
$choiceTranslationDomain
282280
);
283281
}

src/Symfony/Component/Form/Extension/Core/Type/WeekType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ public function configureOptions(OptionsResolver $resolver): void
113113

114114
$choiceTranslationDomainNormalizer = static function (Options $options, $choiceTranslationDomain) {
115115
if (\is_array($choiceTranslationDomain)) {
116-
$default = false;
117-
118116
return array_replace(
119-
['year' => $default, 'week' => $default],
117+
['year' => false, 'week' => false],
120118
$choiceTranslationDomain
121119
);
122120
}

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function validate(mixed $form, Constraint $formConstraint): void
5656
// Validate the data against its own constraints
5757
$validateDataGraph = $form->isRoot()
5858
&& (\is_object($data) || \is_array($data))
59-
&& (($groups && \is_array($groups)) || ($groups instanceof GroupSequence && $groups->groups))
59+
&& (\is_array($groups) || ($groups instanceof GroupSequence && $groups->groups))
6060
;
6161

6262
// Validate the data against the constraints defined in the form

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ public function getPreferredLanguage(?array $locales = null): ?string
15361536
return $preferredLanguages[0] ?? null;
15371537
}
15381538

1539-
$locales = array_map($this->formatLocale(...), $locales ?? []);
1539+
$locales = array_map($this->formatLocale(...), $locales);
15401540
if (!$preferredLanguages) {
15411541
return $locales[0];
15421542
}

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private function getContainerDeprecationLogs(): array
191191
$log['priorityName'] = 'DEBUG';
192192
$log['channel'] = null;
193193
$log['scream'] = false;
194-
unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['trace'], $log['count']);
194+
unset($log['type'], $log['file'], $log['line'], $log['trace'], $log['count']);
195195
$logs[] = $log;
196196
}
197197

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public static function fromDsn(#[\SensitiveParameter] string $dsn, array $option
293293
}
294294

295295
if (isset($params['host'])) {
296-
$options['host'] = $params['host'] ?? $options['host'];
296+
$options['host'] = $params['host'];
297297
$options['port'] = $params['port'] ?? $options['port'];
298298

299299
$pathParts = explode('/', rtrim($params['path'] ?? '', '/'));

src/Symfony/Component/Notifier/Bridge/ContactEveryone/ContactEveryoneTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function doSend(MessageInterface $message): SentMessage
9696
$result = $response->getContent(false);
9797

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

101101
return $sentMessage;
102102
}

src/Symfony/Component/Security/Http/EventListener/SessionStrategyListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function onSuccessfulLogin(LoginSuccessEvent $event): void
4545
$user = $token->getUserIdentifier();
4646
$previousUser = $previousToken->getUserIdentifier();
4747

48-
if ('' !== ($user ?? '') && $user === $previousUser && $token::class === $previousToken::class) {
48+
if ('' !== $user && $user === $previousUser && $token::class === $previousToken::class) {
4949
return;
5050
}
5151
}

src/Symfony/Component/String/Tests/Inflector/SpanishInflectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function testPluralize(string $singular, $plural)
151151
public function testUninflected(string $word)
152152
{
153153
$this->assertSame(
154-
\is_array($word) ? $word : [$word],
154+
[$word],
155155
(new SpanishInflector())->pluralize($word)
156156
);
157157
}

src/Symfony/Component/String/UnicodeString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function splice(string $replacement, int $start = 0, ?int $length = null)
286286
$str = clone $this;
287287

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

292292
if (normalizer_is_normalized($str->string)) {

src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ private function createCommand($requireStrictFileNames = true, $application = nu
215215

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

218-
if ($application) {
219-
$command->setApplication($application);
220-
}
218+
$command->setApplication($application);
221219

222220
return $command;
223221
}

src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ public function testPayloadIsPassedToCallback()
246246
$constraint = new Callback(callback: $callback, payload: 'Hello world!');
247247
$this->validator->validate($object, $constraint);
248248
$this->assertEquals('Hello world!', $payloadCopy);
249-
$payloadCopy = 'Replace me!';
250249

251250
$payloadCopy = 'Replace me!';
252251
$constraint = new Callback([

0 commit comments

Comments
 (0)
0