8000 minor #45902 Leverage non-capturing catches (fancyweb) · symfony/symfony@3d00baf · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 3d00baf

Browse files
committed
minor #45902 Leverage non-capturing catches (fancyweb)
This PR was merged into the 6.1 branch. Discussion ---------- Leverage non-capturing catches | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 9c3bdb7 Leverage non-capturing catches
2 parents 9fbe216 + 9c3bdb7 commit 3d00baf

File tree

171 files changed

+283
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+283
-283
lines changed

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ protected function getMetadata(string $class)
176176
foreach ($this->registry->getManagers() as $name => $em) {
177177
try {
178178
return $this->cache[$class] = [$em->getClassMetadata($class), $name];
179-
} catch (MappingException $e) {
179+
} catch (MappingException) {
180180
// not an entity or mapped super class
181-
} catch (LegacyMappingException $e) {
181+
} catch (LegacyMappingException) {
182182
// not an entity or mapped super class, using Doctrine ORM 2.2
183183
}
184184
}

src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private function pingConnection(EntityManagerInterface $entityManager)
3939

4040
try {
4141
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
42-
} catch (DBALException $e) {
42+
} catch (DBALException) {
4343
$connection->close();
4444
$connection->connect();
4545
}

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function getMetadata(string $class): ?ClassMetadata
212212
{
213213
try {
214214
return $this->entityManager->getClassMetadata($class);
215-
} catch (MappingException|OrmMappingException $exception) {
215+
} catch (MappingException|OrmMappingException) {
216216
return null;
217217
}
218218
}

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function verifyToken(PersistentTokenInterface $token, string $tokenValue)
163163
// we also accept it as a valid value.
164164
try {
165165
$tmpToken = $this->loadTokenBySeries($tmpSeries);
166-
} catch (TokenNotFoundException $e) {
166+
} catch (TokenNotFoundException) {
167167
return false;
168168
}
169169

src/Symfony/Bridge/Doctrine/Types/AbstractUidType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
8080

8181
try {
8282
return $this->getUidClass()::fromString($value)->$toString();
83-
} catch (\InvalidArgumentException $e) {
83+
} catch (\InvalidArgumentException) {
8484
throw ConversionException::conversionFailed($value, $this->getName());
8585
}
8686
}

src/Symfony/Bridge/Doctrine/Validator/DoctrineLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
5050
$className = $metadata->getClassName();
5151
try {
5252
$doctrineMetadata = $this->entityManager->getClassMetadata($className);
53-
} catch (MappingException|OrmMappingException $exception) {
53+
} catch (MappingException|OrmMappingException) {
5454
return false;
5555
}
5656

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function getFlashes(string|array $types = null): array
139139
if (null === $session = $this->getSession()) {
140140
return [];
141141
}
142-
} catch (\RuntimeException $e) {
142+
} catch (\RuntimeException) {
143143
return [];
144144
}
145145

src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function lateCollect()
7171
if ($profile->isTemplate()) {
7272
try {
7373
$template = $this->twig->load($name = $profile->getName());
74-
} catch (LoaderError $e) {
74+
} catch (LoaderError) {
7575
$template = null;
7676
}
7777

src/Symfony/Bridge/Twig/Extension/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function isGranted(mixed $role, mixed $object = null, string $field = nul
4646

4747
try {
4848
return $this->securityChecker->isGranted($role, $object);
49-
} catch (AuthenticationCredentialsNotFoundException $e) {
49+
} catch (AuthenticationCredentialsNotFoundException) {
5050
return false;
5151
}
5252
}

src/Symfony/Bridge/Twig/Mime/BodyRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function getFingerPrint(TemplatedEmail $message): string
8585
$payload = [$messageContext, $message->getTextTemplate(), $message->getHtmlTemplate()];
8686
try {
8787
$serialized = serialize($payload);
88-
} catch (\Exception $e) {
88+
} catch (\Exception) {
8989
// Serialization of 'Closure' is not allowed
9090
// Happens when context contain a closure, in that case, we assume that context always change.
9191
$serialized = random_bytes(8);

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function extract($resource, MessageCatalogue $catalogue)
5353
foreach ($this->extractFiles($resource) as $file) {
5454
try {
5555
$this->extractTemplate(file_get_contents($file->getPathname()), $catalogue);
56-
} catch (Error $e) {
56+
} catch (Error) {
5757
// ignore errors, these should be fixed by using the linter
5858
}
5959
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ final protected function ignoreAutoloadException(string $class, \Exception $exce
7878
{
7979
try {
8080
ClassExistenceResource::throwOnRequiredClass($class, $exception);
81-
} catch (\ReflectionException $e) {
81+
} catch (\ReflectionException) {
8282
}
8383
}
8484

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function readAllComponents(Reader $reader, string $class)
8585

8686
try {
8787
$reader->getClassAnnotations($reflectionClass);
88-
} catch (AnnotationException $e) {
88+
} catch (AnnotationException) {
8989
/*
9090
* Ignore any AnnotationException to not break the cache warming process if an Annotation is badly
9191
* configured or could not be found / read / etc.
@@ -99,14 +99,14 @@ private function readAllComponents(Reader $reader, string $class)
9999
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
100100
try {
101101
$reader->getMethodAnnotations($reflectionMethod);
102-
} catch (AnnotationException $e) {
102+
} catch (AnnotationException) {
103103
}
104104
}
105105

106106
foreach ($reflectionClass->getProperties() as $reflectionProperty) {
107107
try {
108108
$reader->getPropertyAnnotations($reflectionProperty);
109-
} catch (AnnotationException $e) {
109+
} catch (AnnotationException) {
110110
}
111111
}
112112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
5454
foreach ($loader->getMappedClasses() as $mappedClass) {
5555
try {
5656
$metadataFactory->getMetadataFor($mappedClass);
57-
} catch (AnnotationException $e) {
57+
} catch (AnnotationException) {
5858
// ignore failing annotations
5959
} catch (\Exception $e) {
6060
$this->ignoreAutoloadException($mappedClass, $e);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter): bool
5757
if ($metadataFactory->hasMetadataFor($mappedClass)) {
5858
$metadataFactory->getMetadataFor($mappedClass);
5959
}
60-
} catch (AnnotationException $e) {
60+
} catch (AnnotationException) {
6161
// ignore failing annotations
6262
} catch (\Exception $e) {
6363
$this->ignoreAutoloadException($mappedClass, $e);

src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private function relativeSymlinkWithFallback(string $originDir, string $targetDi
202202
try {
203203
$this->symlink($originDir, $targetDir, true);
204204
$method = self::METHOD_RELATIVE_SYMLINK;
205-
} catch (IOException $e) {
205+
} catch (IOException) {
206206
$method = $this->absoluteSymlinkWithFallback($originDir, $targetDir);
207207
}
208208

@@ -219,7 +219,7 @@ private function absoluteSymlinkWithFallback(string $originDir, string $targetDi
219219
try {
220220
$this->symlink($originDir, $targetDir);
221221
$method = self::METHOD_ABSOLUTE_SYMLINK;
222-
} catch (IOException $e) {
222+
} catch (IOException) {
223223
// fall back to copy
224224
$method = $this->hardCopy($originDir, $targetDir);
225225
}

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
195195
$config = $this->getConfig($this->findExtension($name), $this->compileContainer());
196196
$paths = array_keys(self::buildPathsCompletion($config));
197197
$suggestions->suggestValues($paths);
198-
} catch (LogicException $e) {
198+
} catch (LogicException) {
199199
}
200200
}
201201
}

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
153153
if ($this->defaultViewsPath) {
154154
$codePaths[] = $this->defaultViewsPath;
155155
}
156-
} catch (\InvalidArgumentException $e) {
156+
} catch (\InvalidArgumentException) {
157157
// such a bundle does not exist, so treat the argument as path
158158
$path = $input->getArgument('bundle');
159159

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
186186
$codePaths[] = $this->defaultViewsPath;
187187
}
188188
$currentName = $foundBundle->getName();
189-
} catch (\InvalidArgumentException $e) {
189+
} catch (\InvalidArgumentException) {
190190
// such a bundle does not exist, so treat the argument as path
191191
$path = $input->getArgument('bundle');
192192

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public static function getClassDescription(string $class, string &$resolvedClass
299299

300300
return trim(preg_replace('#\s*\n\s*\*\s*#', ' ', $docComment));
301301
}
302-
} catch (\ReflectionException $e) {
302+
} catch (\ReflectionException) {
303303
}
304304

305305
return '';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ private function formatControllerLink(mixed $controller, string $anchorText, cal
563563
} else {
564564
$r = new \ReflectionFunction($controller);
565565
}
566-
} catch (\ReflectionException $e) {
566+
} catch (\ReflectionException) {
567567
if (\is_array($controller)) {
568568
$controller = implode('::', $controller);
569569
}
@@ -582,7 +582,7 @@ private function formatControllerLink(mixed $controller, string $anchorText, cal
582582

583583
try {
584584
$r = new \ReflectionMethod($container->findDefinition($id)->getClass(), $method);
585-
} catch (\ReflectionException $e) {
585+
} catch (\ReflectionException) {
586586
return $anchorText;
587587
}
588588
}

src/Symfony/Bundle/FrameworkBundle/Routing/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getRouteCollection(): RouteCollection
7676
} else {
7777
$this->collection->addResource(new FileExistenceResource($containerFile));
7878
}
79-
} catch (ParameterNotFoundException $exception) {
79+
} catch (ParameterNotFoundException) {
8080
}
8181
}
8282

src/Symfony/Bundle/FrameworkBundle/Secrets/SodiumVault.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function generateKeys(bool $override = false): bool
5151

5252
try {
5353
$this->loadKeys();
54-
} catch (\RuntimeException $e) {
54+
} catch (\RuntimeException) {
5555
// ignore failures to load keys
5656
}
5757

src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected static function createClient(array $options = [], array $server = []):
4545

4646
try {
4747
$client = $kernel->getContainer()->get('test.client');
48-
} catch (ServiceNotFoundException $e) {
48+
} catch (ServiceNotFoundException) {
4949
if (class_exists(KernelBrowser::class)) {
5050
throw new \LogicException('You cannot create the client used in functional tests if the "framework.test" config is not set to true.');
5151
}

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function collect(Request $request, Response $response, \Throwable $except
111111
$logoutUrl = null;
112112
try {
113113
$logoutUrl = $this->logoutUrlGenerator?->getLogoutPath();
114-
} catch (\Exception $e) {
114+
} catch (\Exception) {
115115
// fail silently when the logout URL cannot be generated
116116
}
117117

src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheWarmer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function warmUp(string $cacheDir): array
5353
if (\is_callable([$template, 'unwrap'])) {
5454
$files[] = (new \ReflectionClass($template->unwrap()))->getFileName();
5555
}
56-
} catch (Error $e) {
56+
} catch (Error) {
5757
/*
5858
* Problem during compilation, give up for this template (e.g. syntax errors).
5959
* Failing silently here allows to ignore templates that rely on functions that aren't available in

src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function toolbarAction(Request $request, string $token = null): Response
146146
$url = null;
147147
try {
148148
$url = $this->generator->generate('_profiler', ['token' => $token], UrlGeneratorInterface::ABSOLUTE_URL);
149-
} catch (\Exception $e) {
149+
} catch (\Exception) {
150150
// the profiler is not enabled
151151
}
152152

src/Symfony/Component/BrowserKit/CookieJar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function updateFromSetCookie(array $setCookies, string $uri = null)
122122
foreach ($cookies as $cookie) {
123123
try {
124124
$this->set(Cookie::fromString($cookie, $uri));
125-
} catch (\InvalidArgumentException $e) {
125+
} catch (\InvalidArgumentException) {
126126
// invalid cookies are just ignored
127127
}
128128
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ public function deleteItems(array $keys): bool
253253
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
254254
}
255255
}
256-
} catch (\Exception $e) {
256+
} catch (\Exception) {
257257
$ok = false;
258258
}
259259

260260
try {
261261
if ((!$tagData || $this->doDeleteTagRelations($tagData)) && $ok) {
262262
return true;
263263
}
264-
} catch (\Exception $e) {
264+
} catch (\Exception) {
265265
}
266266

267267
// When bulk-delete failed, retry each item individually

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected function doFetch(array $ids): array
140140
foreach ($ids as $id) {
141141
try {
142142
$resultCouchbase = $this->connection->get($id);
143-
} catch (DocumentNotFoundException $exception) {
143+
} catch (DocumentNotFoundException) {
144144
continue;
145145
}
146146

@@ -181,7 +181,7 @@ protected function doDelete(array $ids): bool
181181
if (null === $result->mutationToken()) {
182182
$idsErrors[] = $id;
183183
}
184-
} catch (DocumentNotFoundException $exception) {
184+
} catch (DocumentNotFoundException) {
185185
}
186186
}
187187

@@ -204,7 +204,7 @@ protected function doSave(array $values, $lifetime): array|bool
204204
foreach ($values as $key => $value) {
205205
try {
206206
$this->connection->upsert($key, $value, $upsertOptions);
207-
} catch (\Exception $exception) {
207+
} catch (\Exception) {
208208
$ko[$key] = '';
209209
}
210210
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function prune(): bool
132132

133133
try {
134134
$this->conn->executeStatement($deleteSql, $params, $paramTypes);
135-
} catch (TableNotFoundException $e) {
135+
} catch (TableNotFoundException) {
136136
}
137137

138138
return true;
@@ -209,7 +209,7 @@ protected function doClear(string $namespace): bool
209209

210210
try {
211211
$this->conn->executeStatement($sql);
212-
} catch (TableNotFoundException $e) {
212+
} catch (TableNotFoundException) {
213213
}
214214

215215
return true;
@@ -223,7 +223,7 @@ protected function doDelete(array $ids): bool
223223
$sql = "DELETE FROM $this->table WHERE $this->idCol IN (?)";
224224
try {
225225
$this->conn->executeStatement($sql, [array_values($ids)], [Connection::PARAM_STR_ARRAY]);
226-
} catch (TableNotFoundException $e) {
226+
} catch (TableNotFoundException) {
227227
}
228228

229229
return true;
@@ -274,7 +274,7 @@ protected function doSave(array $values, int $lifetime): array|bool
274274
$lifetime = $lifetime ?: null;
275275
try {
276276
$stmt = $this->conn->prepare($sql);
277-
} catch (TableNotFoundException $e) {
277+
} catch (TableNotFoundException) {
278278
if (!$this->conn->isTransactionActive() || \in_array($platformName, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
279279
$this->createTable();
280280
}
@@ -312,7 +312,7 @@ protected function doSave(array $values, int $lifetime): array|bool
312312
foreach ($values as $id => $data) {
313313
try {
314314
$rowCount = $stmt->executeStatement();
315-
} catch (TableNotFoundException $e) {
315+
} catch (TableNotFoundException) {
316316
if (!$this->conn->isTransactionActive() || \in_array($platformName, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
317317
$this->createTable();
318318
}
@@ -321,7 +321,7 @@ protected function doSave(array $values, int $lifetime): array|bool
321321
if (null === $platformName && 0 === $rowCount) {
322322
try {
323323
$insertStmt->executeStatement();
324-
} catch (DBALException $e) {
324+
} catch (DBALException) {
325325
// A concurrent write won, let it be
326326
}
327327
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected function doDeleteYieldTags(array $ids): iterable
159159

160160
try {
161161
yield $id => '' === $meta ? [] : $this->marshaller->unmarshall($meta);
162-
} catch (\Exception $e) {
162+
} catch (\Exception) {
163163
yield $id => [];
164164
}
165165
}

0 commit comments

Comments
 (0)
0