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