Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -14,6 +14,12 @@ declare(strict_types=1);
namespace Carbon\PHPStan;
use Closure;
use InvalidArgumentException;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter as AdapterReflectionParameter;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionType as AdapterReflectionType;
use PHPStan\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
use PHPStan\BetterReflection\Reflection\ReflectionFunction as BetterReflectionFunction;
use PHPStan\BetterReflection\Reflection\ReflectionParameter as BetterReflectionParameter;
use PHPStan\Reflection\Php\BuiltinMethodReflection;
use PHPStan\TrinaryLogic;
use ReflectionClass;
@@ -64,24 +70,34 @@ abstract class AbstractMacro implements BuiltinMethodReflection
/**
* Macro constructor.
*
* @param string $className
* @phpstan-param class-string $className
*
* @param string $methodName
* @param callable $macro
* @param class-string $className
* @param string $methodName
* @param callable $macro
*/
public function __construct(string $className, string $methodName, $macro)
{
$this->className = $className;
$this->methodName = $methodName;
$this->reflectionFunction = \is_array($macro)
$rawReflectionFunction = \is_array($macro)
? new ReflectionMethod($macro[0], $macro[1])
: new ReflectionFunction($macro);
$this->parameters = $this->reflectionFunction->getParameters();
$this->reflectionFunction = self::hasModernParser()
? $this->getReflectionFunction($macro)
: $rawReflectionFunction; // @codeCoverageIgnore
$this->parameters = array_map(
function ($parameter) {
if ($parameter instanceof BetterReflectionParameter) {
return new AdapterReflectionParameter($parameter);
}
if ($this->reflectionFunction->isClosure()) {
return $parameter; // @codeCoverageIgnore
},
$this->reflectionFunction->getParameters()
);
if ($rawReflectionFunction->isClosure()) {
try {
$closure = $this->reflectionFunction->getClosure();
$closure = $rawReflectionFunction->getClosure();
$boundClosure = Closure::bind($closure, new stdClass());
$this->static = (!$boundClosure || (new ReflectionFunction($boundClosure))->getClosureThis() === null);
} catch (Throwable $e) {
@@ -90,6 +106,31 @@ abstract class AbstractMacro implements BuiltinMethodReflection
}
}
private function getReflectionFunction($spec)
{
if (\is_array($spec) && \count($spec) === 2 && \is_string($spec[1])) {
\assert($spec[1] !== '');
if (\is_object($spec[0])) {
return BetterReflectionClass::createFromInstance($spec[0])
->getMethod($spec[1]);
}
return BetterReflectionClass::createFromName($spec[0])
->getMethod($spec[1]);
}
if (\is_string($spec)) {
return BetterReflectionFunction::createFromName($spec);
}
if ($spec instanceof Closure) {
return BetterReflectionFunction::createFromClosure($spec);
}
throw new InvalidArgumentException('Could not create reflection from the spec given'); // @codeCoverageIgnore
}
/**
* {@inheritdoc}
*/
@@ -175,7 +216,13 @@ abstract class AbstractMacro implements BuiltinMethodReflection
*/
public function getReturnType(): ?ReflectionType
{
return $this->reflectionFunction->getReturnType();
$type = $this->reflectionFunction->getReturnType();
if ($type instanceof ReflectionType) {
return $type; // @codeCoverageIgnore
}
return self::adaptType($type);
}
/**
@@ -205,18 +252,35 @@ abstract class AbstractMacro implements BuiltinMethodReflection
return $this;
}
/**
* {@inheritdoc}
*/
public function getReflection(): ?ReflectionMethod
{
return $this->reflectionFunction instanceof ReflectionMethod
? $this->reflectionFunction
: null;
}
public function getTentativeReturnType(): ?ReflectionType
{
return null;
}
public function returnsByReference(): TrinaryLogic
{
return TrinaryLogic::createNo();
}
private static function adaptType($type)
{
$method = method_exists(AdapterReflectionType::class, 'fromTypeOrNull')
? 'fromTypeOrNull'
: 'fromReturnTypeOrNull'; // @codeCoverageIgnore
return AdapterReflectionType::$method($type);
}
private static function hasModernParser(): bool
{
static $modernParser = null;
if ($modernParser !== null) {
return $modernParser;
}
$modernParser = method_exists(AdapterReflectionType::class, 'fromTypeOrNull');
return $modernParser;
}
}