1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Reflection;
4:
5: use PHPStan\PhpDoc\ResolvedPhpDocBlock;
6: use PHPStan\TrinaryLogic;
7: use PHPStan\Turbo\ReferencedByTurboExtension;
8: use PHPStan\Type\Type;
9:
10: /**
11: * Extended method reflection with additional metadata beyond MethodReflection.
12: *
13: * This interface exists to allow PHPStan to add new method query methods in minor
14: * versions without breaking existing MethodsClassReflectionExtension implementations.
15: * Extension developers should implement MethodReflection, not this interface — PHPStan
16: * wraps MethodReflection implementations to provide ExtendedMethodReflection.
17: *
18: * Provides access to:
19: * - Extended parameter signatures (ExtendedParametersAcceptor with PHPDoc/native types)
20: * - Named argument variants (different signatures when using named arguments)
21: * - Type assertions (@phpstan-assert annotations)
22: * - Self-out types (@phpstan-self-out for fluent interfaces)
23: * - Purity information (@phpstan-pure/@phpstan-impure)
24: * - PHP attributes (including #[\NoDiscard])
25: * - Resolved PHPDoc block
26: *
27: * This is the return type of Type::getMethod() and Scope::getMethodReflection().
28: *
29: * @api
30: * @api-do-not-implement
31: */
32: #[ReferencedByTurboExtension(key: 'extendedMethodReflection')]
33: interface ExtendedMethodReflection extends MethodReflection
34: {
35:
36: /** @return list<ExtendedParametersAcceptor> */
37: public function getVariants(): array;
38:
39: /** @internal */
40: public function getOnlyVariant(): ExtendedParametersAcceptor;
41:
42: /**
43: * Returns alternative signatures used when the method is called with named arguments.
44: * Returns null if the named argument variants are the same as regular variants.
45: *
46: * @return list<ExtendedParametersAcceptor>|null
47: */
48: public function getNamedArgumentsVariants(): ?array;
49:
50: public function acceptsNamedArguments(): TrinaryLogic;
51:
52: public function getAsserts(): Assertions;
53:
54: /**
55: * Used for fluent interfaces where calling a method changes the generic
56: * type parameters of $this (e.g. a builder pattern).
57: */
58: public function getSelfOutType(): ?Type;
59:
60: public function returnsByReference(): TrinaryLogic;
61:
62: public function isFinalByKeyword(): TrinaryLogic;
63:
64: public function isAbstract(): TrinaryLogic|bool;
65:
66: public function isBuiltin(): TrinaryLogic|bool;
67:
68: /**
69: * In most cases hasSideEffects() is more practical as it also accounts
70: * for void return type (methods returning void are always impure).
71: */
72: public function isPure(): TrinaryLogic;
73:
74: /**
75: * @return array<string, TrinaryLogic>
76: */
77: public function getPureUnlessCallableIsImpureParameters(): array;
78:
79: /** @return list<AttributeReflection> */
80: public function getAttributes(): array;
81:
82: /**
83: * On PHP 8.5+ if the return value is unused at runtime, a warning is emitted.
84: * PHPStan reports this during analysis regardless of PHP version.
85: */
86: public function mustUseReturnValue(): TrinaryLogic;
87:
88: public function getResolvedPhpDoc(): ?ResolvedPhpDocBlock;
89:
90: }
91: