Skip to content

Commit d729971

Browse files
author
MateuszKolankowski
committed
Removed redundant exception handling, cleaned up unused Throwable imports, and updated phpstan baseline entries.
1 parent e03e8bc commit d729971

File tree

18 files changed

+585
-1245
lines changed

18 files changed

+585
-1245
lines changed

phpstan-baseline-lte-8.3.neon

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,69 @@ parameters:
55
identifier: new.resultUnused
66
count: 1
77
path: tests/lib/Repository/Service/Mock/UrlAliasTest.php
8+
9+
-
10+
message: '#^Dead catch \- Ibexa\\Contracts\\Core\\Repository\\Exceptions\\NotFoundException is never thrown in the try block\.$#'
11+
identifier: catch.neverThrown
12+
count: 1
13+
path: src/bundle/Core/Features/Context/ContentTypeContext.php
14+
15+
-
16+
message: '#^Dead catch \- Ibexa\\Contracts\\Core\\Repository\\Exceptions\\NotFoundException is never thrown in the try block\.$#'
17+
identifier: catch.neverThrown
18+
count: 1
19+
path: src/bundle/Core/Features/Context/UserContext.php
20+
21+
-
22+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
23+
identifier: catch.neverThrown
24+
count: 1
25+
path: src/lib/Persistence/Legacy/Notification/Gateway/ExceptionConversion.php
26+
27+
-
28+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
29+
identifier: catch.neverThrown
30+
count: 1
31+
path: src/lib/Persistence/Legacy/Notification/Gateway/ExceptionConversion.php
32+
33+
-
34+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
35+
identifier: catch.neverThrown
36+
count: 1
37+
path: src/lib/Persistence/Legacy/URL/Gateway/ExceptionConversion.php
38+
39+
-
40+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
41+
identifier: catch.neverThrown
42+
count: 1
43+
path: src/lib/Persistence/Legacy/URL/Gateway/ExceptionConversion.php
44+
45+
-
46+
message: '#^Dead catch \- Exception is never thrown in the try block\.$#'
47+
identifier: catch.neverThrown
48+
count: 1
49+
path: src/lib/Repository/UserPreferenceService.php
50+
51+
-
52+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
53+
identifier: catch.neverThrown
54+
count: 1
55+
path: src/lib/Search/Legacy/Content/Gateway/ExceptionConversion.php
56+
57+
-
58+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
59+
identifier: catch.neverThrown
60+
count: 1
61+
path: src/lib/Search/Legacy/Content/Gateway/ExceptionConversion.php
62+
63+
-
64+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
65+
identifier: catch.neverThrown
66+
count: 1
67+
path: src/lib/Search/Legacy/Content/Location/Gateway/ExceptionConversion.php
68+
69+
-
70+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
71+
identifier: catch.neverThrown
72+
count: 1
73+
path: src/lib/Search/Legacy/Content/Location/Gateway/ExceptionConversion.php

phpstan-baseline.neon

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75515,3 +75515,93 @@ parameters:
7551575515
identifier: phpDoc.parseError
7551675516
count: 1
7551775517
path: tests/lib/Validation/StructValidatorTest.php
75518+
75519+
-
75520+
message: '#^Dead catch \- Ibexa\\Core\\IO\\Exception\\BinaryFileNotFoundException is never thrown in the try block\.$#'
75521+
identifier: catch.neverThrown
75522+
count: 1
75523+
path: src/lib/IO/TolerantIOService.php
75524+
75525+
-
75526+
message: '#^Dead catch \- Ibexa\\Core\\Repository\\User\\Exception\\UnsupportedPasswordHashType is never thrown in the try block\.$#'
75527+
identifier: catch.neverThrown
75528+
count: 1
75529+
path: src/lib/MVC/Symfony/Security/Authentication/RepositoryAuthenticationProvider.php
75530+
75531+
-
75532+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75533+
identifier: catch.neverThrown
75534+
count: 14
75535+
path: src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php
75536+
75537+
-
75538+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75539+
identifier: catch.neverThrown
75540+
count: 14
75541+
path: src/lib/Persistence/Legacy/Content/Gateway/ExceptionConversion.php
75542+
75543+
-
75544+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75545+
identifier: catch.neverThrown
75546+
count: 8
75547+
path: src/lib/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php
75548+
75549+
-
75550+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75551+
identifier: catch.neverThrown
75552+
count: 8
75553+
path: src/lib/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php
75554+
75555+
-
75556+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75557+
identifier: catch.neverThrown
75558+
count: 4
75559+
path: src/lib/Persistence/Legacy/Content/ObjectState/Gateway/ExceptionConversion.php
75560+
75561+
-
75562+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75563+
identifier: catch.neverThrown
75564+
count: 4
75565+
path: src/lib/Persistence/Legacy/Content/ObjectState/Gateway/ExceptionConversion.php
75566+
75567+
-
75568+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75569+
identifier: catch.neverThrown
75570+
count: 4
75571+
path: src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php
75572+
75573+
-
75574+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75575+
identifier: catch.neverThrown
75576+
count: 4
75577+
path: src/lib/Persistence/Legacy/Content/Type/Gateway/ExceptionConversion.php
75578+
75579+
-
75580+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75581+
identifier: catch.neverThrown
75582+
count: 2
75583+
path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php
75584+
75585+
-
75586+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75587+
identifier: catch.neverThrown
75588+
count: 2
75589+
path: src/lib/Persistence/Legacy/Content/UrlAlias/Gateway/ExceptionConversion.php
75590+
75591+
-
75592+
message: '#^Dead catch \- Doctrine\\DBAL\\DBALException is never thrown in the try block\.$#'
75593+
identifier: catch.neverThrown
75594+
count: 1
75595+
path: src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway/ExceptionConversion.php
75596+
75597+
-
75598+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75599+
identifier: catch.neverThrown
75600+
count: 1
75601+
path: src/lib/Persistence/Legacy/Content/UrlWildcard/Gateway/ExceptionConversion.php
75602+
75603+
-
75604+
message: '#^Dead catch \- PDOException is never thrown in the try block\.$#'
75605+
identifier: catch.neverThrown
75606+
count: 5
75607+
path: src/lib/Persistence/Legacy/Setting/Gateway/ExceptionConversion.php

src/bundle/Core/Features/Context/ContentTypeContext.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Ibexa\Contracts\Core\Repository\ContentTypeService;
1212
use Ibexa\Contracts\Core\Repository\Exceptions as ApiExceptions;
1313
use PHPUnit\Framework\Assert as Assertion;
14-
use Throwable;
1514

1615
/**
1716
* Sentences for content types.
@@ -123,15 +122,18 @@ public function assertContentTypeExistsByIdentifierOnGroup($identifier, $groupId
123122
*/
124123
protected function loadContentTypeByIdentifier($identifier, $throwIfNotFound = true)
125124
{
125+
$contentType = null;
126126
try {
127-
return $this->contentTypeService->loadContentTypeByIdentifier($identifier);
128-
} catch (Throwable $e) {
129-
if ($e instanceof ApiExceptions\NotFoundException && !$throwIfNotFound) {
130-
return null;
131-
}
127+
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($identifier);
128+
} catch (ApiExceptions\NotFoundException $e) {
129+
$notFoundException = $e;
130+
}
132131

133-
throw $e;
132+
if (!$contentType && $throwIfNotFound) {
133+
throw $notFoundException;
134134
}
135+
136+
return $contentType;
135137
}
136138

137139
/**
@@ -196,10 +198,8 @@ protected function removeContentType($contentType)
196198
{
197199
try {
198200
$this->contentTypeService->deleteContentType($contentType);
199-
} catch (Throwable $e) {
200-
if (!$e instanceof ApiExceptions\NotFoundException) {
201-
throw $e;
202-
}
201+
} catch (ApiExceptions\NotFoundException $e) {
202+
// nothing to do
203203
}
204204
}
205205

src/bundle/Core/Features/Context/UserContext.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Ibexa\Contracts\Core\Repository\Values\Content\Query;
1616
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
1717
use PHPUnit\Framework\Assert as Assertion;
18-
use Throwable;
1918

2019
/**
2120
* Sentences for Users.
@@ -58,12 +57,8 @@ public function searchUserByLogin($username, $parentGroupId = null)
5857
{
5958
try {
6059
$user = $this->userService->loadUserByLogin($username);
61-
} catch (Throwable $e) {
62-
if ($e instanceof ApiExceptions\NotFoundException) {
63-
return null;
64-
}
65-
66-
throw $e;
60+
} catch (ApiExceptions\NotFoundException $e) {
61+
return null;
6762
}
6863

6964
if ($user && $parentGroupId) {
@@ -135,10 +130,8 @@ protected function createUser($username, $email, $password, $parentGroup = null,
135130
try {
136131
$existingUser = $this->userService->loadUserByLogin($username);
137132
$this->userService->deleteUser($existingUser);
138-
} catch (Throwable $e) {
139-
if (!$e instanceof NotFoundException) {
140-
throw $e;
141-
}
133+
} catch (NotFoundException $e) {
134+
// do nothing
142135
}
143136

144137
if (!$parentGroup) {
@@ -244,19 +237,15 @@ public function ensureUserDoesntExist($username, $parentGroupName = null)
244237
} else {
245238
try {
246239
$user = $this->userService->loadUserByLogin($username);
247-
} catch (Throwable $e) {
248-
if (!$e instanceof ApiExceptions\NotFoundException) {
249-
throw $e;
250-
}
240+
} catch (ApiExceptions\NotFoundException $e) {
241+
// nothing to do
251242
}
252243
}
253244
if ($user) {
254245
try {
255246
$this->userService->deleteUser($user);
256-
} catch (Throwable $e) {
257-
if (!$e instanceof ApiExceptions\NotFoundException) {
258-
throw $e;
259-
}
247+
} catch (ApiExceptions\NotFoundException $e) {
248+
// nothing to do
260249
}
261250
}
262251
}

src/lib/IO/TolerantIOService.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Ibexa\Core\IO\Values\BinaryFile;
1313
use Ibexa\Core\IO\Values\MissingBinaryFile;
1414
use Psr\Log\LoggerInterface;
15-
use Throwable;
1615

1716
/**
1817
* An extended IOService that tolerates physically missing files.
@@ -111,17 +110,13 @@ public function loadBinaryFileByUri($binaryFileUri)
111110

112111
try {
113112
return $this->loadBinaryFile($binaryFileId);
114-
} catch (Throwable $e) {
115-
if ($e instanceof BinaryFileNotFoundException) {
116-
$this->logMissingFile($binaryFileUri);
117-
118-
return new MissingBinaryFile([
119-
'id' => $binaryFileId,
120-
'uri' => $this->binarydataHandler->getUri($this->getPrefixedUri($binaryFileId)),
121-
]);
122-
}
113+
} catch (BinaryFileNotFoundException $e) {
114+
$this->logMissingFile($binaryFileUri);
123115

124-
throw $e;
116+
return new MissingBinaryFile([
117+
'id' => $binaryFileId,
118+
'uri' => $this->binarydataHandler->getUri($this->getPrefixedUri($binaryFileId)),
119+
]);
125120
}
126121
}
127122

src/lib/MVC/Symfony/Security/Authentication/RepositoryAuthenticationProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,11 @@ public function authenticate(TokenInterface $token)
9090

9191
try {
9292
$result = parent::authenticate($token);
93+
} catch (UnsupportedPasswordHashType $exception) {
94+
$this->sleepUsingConstantTimer($startTime);
95+
throw new PasswordInUnsupportedFormatException($exception);
9396
} catch (\Exception $e) {
9497
$this->sleepUsingConstantTimer($startTime);
95-
if ($e instanceof UnsupportedPasswordHashType) {
96-
throw new PasswordInUnsupportedFormatException($e);
97-
}
98-
9998
throw $e;
10099
}
101100

0 commit comments

Comments
 (0)