| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Type; |
| 4: | |
| 5: | use PhpParser\Node\Expr\FuncCall; |
| 6: | use PHPStan\Analyser\Scope; |
| 7: | use PHPStan\DependencyInjection\ExtensionInterface; |
| 8: | use PHPStan\Reflection\FunctionReflection; |
| 9: | use PHPStan\Reflection\SideEffects; |
| 10: | |
| 11: | /** |
| 12: | * This is the interface dynamic side effects extensions implement for functions. |
| 13: | * They describe the side effects of one call, such as a function that prints |
| 14: | * only for some arguments. They do not include the effects of the callables |
| 15: | * passed to the parameters flagged with @pure-unless-callable-is-impure, the |
| 16: | * analysis adds those. |
| 17: | * |
| 18: | * The returned side effects replace the ones of the reflection for this call: |
| 19: | * whether it writes the object or class it is called on, which global state |
| 20: | * it forgets, whether its result is remembered, and whether it is pure. Like |
| 21: | * a functionMetadata entry, the call forgets global state only as far as it |
| 22: | * lists writes-global or a part of it. The arguments it writes are still the |
| 23: | * ones of the reflection: they are decided while the arguments are processed. |
| 24: | * |
| 25: | * To register it in the configuration file use the `phpstan.dynamicFunctionSideEffectsExtension` service tag: |
| 26: | * |
| 27: | * ``` |
| 28: | * services: |
| 29: | * - |
| 30: | * class: App\PHPStan\MyExtension |
| 31: | * tags: |
| 32: | * - phpstan.dynamicFunctionSideEffectsExtension |
| 33: | * ``` |
| 34: | * |
| 35: | * @api |
| 36: | */ |
| 37: | #[ExtensionInterface(tag: 'phpstan.dynamicFunctionSideEffectsExtension')] |
| 38: | interface DynamicFunctionSideEffectsExtension |
| 39: | { |
| 40: | |
| 41: | public function isFunctionSupported(FunctionReflection $functionReflection): bool; |
| 42: | |
| 43: | /** null keeps the side effects the function reflection describes */ |
| 44: | public function getSideEffectsFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?SideEffects; |
| 45: | |
| 46: | } |
| 47: |