declaringClass = $declaringClass; $this->name = $name; $this->class = $declaringClass->getName(); $this->isStatic = $isStatic; $this->returnType = $returnType; $this->parameters = $parameters; $this->description = $description; $this->returnsReference = $returnsReference; } /** * Get the method name. */ public function getName(): string { return $this->name; } /** * Get the class that declares this method. */ public function getDeclaringClass(): \ReflectionClass { return $this->declaringClass; } /** * Check if this is a static method. */ public function isStatic(): bool { return $this->isStatic; } /** * Magic methods are always public. */ public function isPublic(): bool { return true; } /** * Magic methods are never protected. */ public function isProtected(): bool { return false; } /** * Magic methods are never private. */ public function isPrivate(): bool { return false; } /** * Magic methods are never abstract. */ public function isAbstract(): bool { return false; } /** * Magic methods are never final. */ public function isFinal(): bool { return false; } /** * Check if this method returns by reference. */ public function returnsReference(): bool { return $this->returnsReference; } /** * Get the method modifiers. */ public function getModifiers(): int { $modifiers = \ReflectionMethod::IS_PUBLIC; if ($this->isStatic) { $modifiers |= \ReflectionMethod::IS_STATIC; } return $modifiers; } /** * Get parameters - returns empty array since we only have a string representation. * * @return \ReflectionParameter[] */ public function getParameters(): array { return []; } /** * Get the raw parameter string from the docblock. */ public function getParameterString(): string { return $this->parameters; } /** * Get the return type from the docblock. */ public function getDocblockReturnType(): ?string { return $this->returnType; } /** * Get the description from the docblock. */ public function getDescription(): ?string { return $this->description; } /** * Magic methods don't have a native return type. */ public function hasReturnType(): bool { return false; } /** * Magic methods don't have a native return type. */ public function getReturnType(): ?\ReflectionType { return null; } /** * Get the docblock for this magic method. * * Returns the description if available. * * @return string|false */ public function getDocComment() { if ($this->description === null) { return false; } return \sprintf("/**\n * %s\n */", $this->description); } /** * Export is not supported. * * @throws \RuntimeException */ public static function export($class, $name, $return = false): ?string { throw new \RuntimeException('Export is not supported for magic methods'); } /** * String representation. */ public function __toString(): string { $static = $this->isStatic ? 'static ' : ''; $return = $this->returnType ? $this->returnType.' ' : ''; $ref = $this->returnsReference ? '&' : ''; return \sprintf( 'Method [ public %s%smethod %s%s ] { %s%s(%s) }', $static, $return, $ref, $this->name, $ref, $this->name, $this->parameters ); } }