mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02:00
Pushing latest stuff
This commit is contained in:
57
php-packages/phpstan/src/Methods/Extension.php
Normal file
57
php-packages/phpstan/src/Methods/Extension.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Flarum\PHPStan\Methods;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Reflection\MethodReflection;
|
||||
use PHPStan\Reflection\MethodsClassReflectionExtension;
|
||||
use PHPStan\Reflection\Php\PhpMethodReflectionFactory;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Extension implements MethodsClassReflectionExtension
|
||||
{
|
||||
/**
|
||||
* @var Kernel
|
||||
*/
|
||||
private $kernel;
|
||||
|
||||
/** @var MethodReflection[] */
|
||||
private $methodReflections = [];
|
||||
|
||||
public function __construct(PhpMethodReflectionFactory $methodReflectionFactory, ReflectionProvider $reflectionProvider, Kernel $kernel = null)
|
||||
{
|
||||
$this->kernel = $kernel ?? new Kernel($methodReflectionFactory, $reflectionProvider);
|
||||
}
|
||||
|
||||
public function hasMethod(ClassReflection $classReflection, string $methodName): bool
|
||||
{
|
||||
if ($classReflection->getName() === Model::class) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array_key_exists($methodName.'-'.$classReflection->getName(), $this->methodReflections)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$passable = $this->kernel->handle($classReflection, $methodName);
|
||||
|
||||
$found = $passable->hasFound();
|
||||
|
||||
if ($found) {
|
||||
$this->methodReflections[$methodName.'-'.$classReflection->getName()] = $passable->getMethodReflection();
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
|
||||
{
|
||||
return $this->methodReflections[$methodName.'-'.$classReflection->getName()];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user