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-32Lines changed: 14 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -49,29 +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
-
call_user_func: 0
69
-
call_user_func_array: 0
70
-
forward_static_call: 0
71
-
forward_static_call_array: 0
72
-
uasort: 1
73
-
uksort: 1
74
-
usort: 1
75
52
allowedCheckedExceptionCallables: []
76
53
forbidCheckedExceptionInYieldingMethod:
77
54
enabled: true
@@ -350,8 +327,7 @@ parameters:
350
327
351
328
### forbidCheckedExceptionInCallable
352
329
- 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
353
-
- 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 (!)
354
-
- By default, native functions like `array_map` are present. So it is recommended not to overwrite the defaults here (by `!` char).
330
+
- 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))
355
331
- 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
356
332
- It ignores [implicitly thrown Throwable](https://phpstan.org/blog/bring-your-exceptions-under-control#what-does-absent-%40throws-above-a-function-mean%3F)
357
333
- Learn more in 🇨🇿 [talk about checked exceptions in general](https://www.youtube.com/watch?v=UQsP1U0sVZM)
@@ -360,10 +336,6 @@ parameters:
360
336
parameters:
361
337
shipmonkRules:
362
338
forbidCheckedExceptionInCallable:
363
-
immediatelyCalledCallables:
364
-
'Doctrine\ORM\EntityManager::transactional': 0 # 0 is argument index where the closure appears, you can use list if needed
365
-
'Symfony\Contracts\Cache\CacheInterface::get': 1
366
-
'Acme\my_custom_function': 0
367
339
allowedCheckedExceptionCallables:
368
340
'Symfony\Component\Console\Question::setValidator': 0 # symfony automatically converts all thrown exceptions to error output, so it is safe to throw anything here
369
341
```
@@ -384,16 +356,26 @@ parameters:
384
356
385
357
386
358
```php
359
+
class TransactionManager {
360
+
/**
361
+
* @param-immediately-invoked-callable $callback
362
+
*/
363
+
public function transactional(callable $callback): void {
364
+
// ...
365
+
$callback();
366
+
// ...
367
+
}
368
+
}
369
+
387
370
class UserEditFacade
388
371
{
389
372
/**
390
373
* @throws UserNotFoundException
391
-
* ^ This throws would normally be reported as never thrown in native phpstan, but we know the closure is immediately called
392
374
*/
393
375
public function updateUserEmail(UserId $userId, Email $email): void
394
376
{
395
-
$this->entityManager->transactional(function () use ($userId, $email) {
0 commit comments