| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Reflection\Callables; |
| 4: | |
| 5: | use PHPStan\Node\InvalidateExprNode; |
| 6: | use PHPStan\Reflection\ParametersAcceptor; |
| 7: | use PHPStan\TrinaryLogic; |
| 8: | |
| 9: | /** |
| 10: | * A ParametersAcceptor for callable types (closures, first-class callables). |
| 11: | * |
| 12: | * Extends ParametersAcceptor with information about side effects, exceptions, |
| 13: | * and other runtime behavior of callable values. This is what PHPStan knows |
| 14: | * about a closure or callable when it's passed as a parameter or stored in a variable. |
| 15: | * |
| 16: | * Implemented by ClosureType and used as the return type of |
| 17: | * Type::getCallableParametersAcceptors(). |
| 18: | * |
| 19: | * Provides: |
| 20: | * - Throw points (what exceptions the callable may throw) |
| 21: | * - Impure points (what side effects the callable may have) |
| 22: | * - Purity information |
| 23: | * - Variables captured from outer scope (used variables) |
| 24: | * - Expressions that are invalidated by calling this callable |
| 25: | * |
| 26: | * @api |
| 27: | * @api-do-not-implement |
| 28: | */ |
| 29: | interface CallableParametersAcceptor extends ParametersAcceptor |
| 30: | { |
| 31: | |
| 32: | /** @return SimpleThrowPoint[] */ |
| 33: | public function getThrowPoints(): array; |
| 34: | |
| 35: | public function isPure(): TrinaryLogic; |
| 36: | |
| 37: | public function acceptsNamedArguments(): TrinaryLogic; |
| 38: | |
| 39: | /** @return SimpleImpurePoint[] */ |
| 40: | public function getImpurePoints(): array; |
| 41: | |
| 42: | /** |
| 43: | * Tracks when calling a closure invalidates cached type information |
| 44: | * for variables it captures by reference. |
| 45: | * |
| 46: | * @return InvalidateExprNode[] |
| 47: | */ |
| 48: | public function getInvalidateExpressions(): array; |
| 49: | |
| 50: | /** @return string[] */ |
| 51: | public function getUsedVariables(): array; |
| 52: | |
| 53: | /** |
| 54: | * Whether the callable is marked with the `#[\NoDiscard]` attribute. |
| 55: | * On PHP 8.5+ if the return value is unused at runtime, a warning is emitted. |
| 56: | * PHPStan reports this during analysis regardless of PHP version. |
| 57: | */ |
| 58: | public function mustUseReturnValue(): TrinaryLogic; |
| 59: | |
| 60: | } |
| 61: |