Aggiornato Composer
This commit is contained in:
@@ -12,35 +12,55 @@
|
||||
namespace Carbon\PHPStan;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
final class MacroScanner
|
||||
{
|
||||
/**
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
|
||||
/**
|
||||
* MacroScanner constructor.
|
||||
*
|
||||
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
|
||||
*/
|
||||
public function __construct(ReflectionProvider $reflectionProvider)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given pair class-method is a Carbon macro.
|
||||
*
|
||||
* @param string $className
|
||||
* @phpstan-param class-string $className
|
||||
*
|
||||
* @param string $methodName
|
||||
* @param class-string $className
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMethod(string $className, string $methodName): bool
|
||||
{
|
||||
return is_a($className, CarbonInterface::class, true) &&
|
||||
\is_callable([$className, 'hasMacro']) &&
|
||||
$classReflection = $this->reflectionProvider->getClass($className);
|
||||
|
||||
if (
|
||||
$classReflection->getName() !== CarbonInterface::class &&
|
||||
!$classReflection->isSubclassOf(CarbonInterface::class)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return \is_callable([$className, 'hasMacro']) &&
|
||||
$className::hasMacro($methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Macro for a given pair class-method.
|
||||
*
|
||||
* @param string $className
|
||||
* @phpstan-param class-string $className
|
||||
*
|
||||
* @param string $methodName
|
||||
* @param class-string $className
|
||||
* @param string $methodName
|
||||
*
|
||||
* @throws ReflectionException
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user