AbstractMacroStatic.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Carbon\PHPStan;
  12. use PHPStan\BetterReflection\Reflection;
  13. use ReflectionMethod;
  14. if (!class_exists(AbstractReflectionMacro::class, false)) {
  15. abstract class AbstractReflectionMacro extends AbstractMacro
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getReflection(): ?Reflection\Adapter\ReflectionMethod
  21. {
  22. if ($this->reflectionFunction instanceof Reflection\Adapter\ReflectionMethod) {
  23. return $this->reflectionFunction;
  24. }
  25. if ($this->reflectionFunction instanceof Reflection\ReflectionMethod) {
  26. return new Reflection\Adapter\ReflectionMethod($this->reflectionFunction);
  27. }
  28. return $this->reflectionFunction instanceof ReflectionMethod
  29. ? new Reflection\Adapter\ReflectionMethod(
  30. Reflection\ReflectionMethod::createFromName(
  31. $this->reflectionFunction->getDeclaringClass()->getName(),
  32. $this->reflectionFunction->getName()
  33. )
  34. )
  35. : null;
  36. }
  37. }
  38. }