-
-
Notifications
You must be signed in to change notification settings - Fork 934
Description
UPDATE:
I uploaded my code to a GitHub repository
Hey everyone,
I need phpstan to support Prophecy, which is why I started work on an extension. I already set up a test case for phpstan that will throw errors, as long as Prophecy is not properly parsed. (TDD ftw!)
However, I have no idea how to get started, really. I figured my main "point of attack" would be the Prophet class, or to be more precise the prophesize() function of that class.
So I figured I needed an MethodsClassReflectionExtension like this:
class ProphetProphesizeReflectionExtension implements MethodsClassReflectionExtension
{
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
return $classReflection->getName() == Prophet::class && $methodName == 'prophesize';
}
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
{
$methodReflection = new ProphesizeMethodReflection();
return $methodReflection;
}
}
Which should return the following MethodRefelction :
class ProphesizeMethodReflection implements MethodReflection
{
public function getDeclaringClass(): ClassReflection
{
return new ClassReflection();
}
public function isStatic(): bool
{
return false;
}
public function isPrivate(): bool
{
false;
}
public function isPublic(): bool
{
true;
}
public function getPrototype(): self
{
return self;
}
public function getName(): string
{
return self::class;
}
/**
* @return \PHPStan\Reflection\ParameterReflection[]
*/
public function getParameters(): array
{
return [];
}
public function isVariadic(): bool
{
return false;
}
public function getReturnType(): Type
{
return new ObjectProphecyType();
}
}
That class however, needs to instantiate a ClassReflection and I have no idea where I should get the required dependencies from. 😱
I was really hoping to get the basics done for my colleagues before I leave for the SymfonyCon conference next week, but I guess that was kind of a moonshot to begin with. Still, I would appreciate any help.