You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-28Lines changed: 14 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -49,25 +49,6 @@ parameters:
49
49
blacklist: ['(array)', '(object)', '(unset)']
50
50
forbidCheckedExceptionInCallable:
51
51
enabled: true
52
-
immediatelyCalledCallables:
53
-
array_reduce: 1
54
-
array_intersect_ukey: 2
55
-
array_uintersect: 2
56
-
array_uintersect_assoc: 2
57
-
array_intersect_uassoc: 2
58
-
array_uintersect_uassoc: [2, 3]
59
-
array_diff_ukey: 2
60
-
array_udiff: 2
61
-
array_udiff_assoc: 2
62
-
array_diff_uassoc: 2
63
-
array_udiff_uassoc: [2, 3]
64
-
array_filter: 1
65
-
array_map: 0
66
-
array_walk_recursive: 1
67
-
array_walk: 1
68
-
uasort: 1
69
-
uksort: 1
70
-
usort: 1
71
52
allowedCheckedExceptionCallables: []
72
53
forbidCheckedExceptionInYieldingMethod:
73
54
enabled: true
@@ -345,19 +326,14 @@ parameters:
345
326
346
327
### forbidCheckedExceptionInCallable
347
328
- Denies throwing [checked exception](https://phpstan.org/blog/bring-your-exceptions-under-control) in callables (Closures, Arrow functions and First class callables) as those cannot be tracked as checked by PHPStan analysis, because it is unknown when the callable is about to be called
348
-
- It allows configuration of functions/methods, where the callable is called immediately, those cases are allowed and are also added to [dynamic throw type extension](https://phpstan.org/developing-extensions/dynamic-throw-type-extensions) which causes those exceptions to be tracked properly in your codebase (!)
349
-
- By default, native functions like `array_map` are present. So it is recommended not to overwrite the defaults here (by `!` char).
329
+
- It is allowed to throw checked exceptions in immediately called callables (e.g. params marked by `@param-immediately-invoked-callable`, see [docs](https://phpstan.org/writing-php-code/phpdocs-basics#callables))
350
330
- It allows configuration of functions/methods, where the callable is handling all thrown exceptions and it is safe to throw anything from there; this basically makes such calls ignored by this rule
351
331
- It ignores [implicitly thrown Throwable](https://phpstan.org/blog/bring-your-exceptions-under-control#what-does-absent-%40throws-above-a-function-mean%3F)
352
332
353
333
```neon
354
334
parameters:
355
335
shipmonkRules:
356
336
forbidCheckedExceptionInCallable:
357
-
immediatelyCalledCallables:
358
-
'Doctrine\ORM\EntityManager::transactional': 0 # 0 is argument index where the closure appears, you can use list if needed
359
-
'Symfony\Contracts\Cache\CacheInterface::get': 1
360
-
'Acme\my_custom_function': 0
361
337
allowedCheckedExceptionCallables:
362
338
'Symfony\Component\Console\Question::setValidator': 0 # symfony automatically converts all thrown exceptions to error output, so it is safe to throw anything here
363
339
```
@@ -378,16 +354,26 @@ parameters:
378
354
379
355
380
356
```php
357
+
class TransactionManager {
358
+
/**
359
+
* @param-immediately-invoked-callable $callback
360
+
*/
361
+
public function transactional(callable $callback): void {
362
+
// ...
363
+
$callback();
364
+
// ...
365
+
}
366
+
}
367
+
381
368
class UserEditFacade
382
369
{
383
370
/**
384
371
* @throws UserNotFoundException
385
-
* ^ This throws would normally be reported as never thrown in native phpstan, but we know the closure is immediately called
386
372
*/
387
373
public function updateUserEmail(UserId $userId, Email $email): void
388
374
{
389
-
$this->entityManager->transactional(function () use ($userId, $email) {
0 commit comments