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