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