Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
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
 
12
namespace Carbon\PHPStan;
13
 
14
use PHPStan\Reflection\Assertions;
15
use PHPStan\Reflection\ClassReflection;
16
use PHPStan\Reflection\MethodReflection;
17
use PHPStan\Reflection\MethodsClassReflectionExtension;
18
use PHPStan\Reflection\Php\PhpMethodReflectionFactory;
19
use PHPStan\Reflection\ReflectionProvider;
20
use PHPStan\Type\TypehintHelper;
21
 
22
/**
23
 * Class MacroExtension.
24
 *
25
 * @codeCoverageIgnore Pure PHPStan wrapper.
26
 */
27
final class MacroExtension implements MethodsClassReflectionExtension
28
{
29
    /**
30
     * @var PhpMethodReflectionFactory
31
     */
32
    protected $methodReflectionFactory;
33
 
34
    /**
35
     * @var MacroScanner
36
     */
37
    protected $scanner;
38
 
39
    /**
40
     * Extension constructor.
41
     *
42
     * @param PhpMethodReflectionFactory $methodReflectionFactory
43
     * @param ReflectionProvider         $reflectionProvider
44
     */
45
    public function __construct(
46
        PhpMethodReflectionFactory $methodReflectionFactory,
47
        ReflectionProvider $reflectionProvider
48
    ) {
49
        $this->scanner = new MacroScanner($reflectionProvider);
50
        $this->methodReflectionFactory = $methodReflectionFactory;
51
    }
52
 
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function hasMethod(ClassReflection $classReflection, string $methodName): bool
57
    {
58
        return $this->scanner->hasMethod($classReflection->getName(), $methodName);
59
    }
60
 
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
65
    {
66
        $builtinMacro = $this->scanner->getMethod($classReflection->getName(), $methodName);
67
        $supportAssertions = class_exists(Assertions::class);
68
 
69
        return $this->methodReflectionFactory->create(
70
            $classReflection,
71
            null,
72
            $builtinMacro,
73
            $classReflection->getActiveTemplateTypeMap(),
74
            [],
75
            TypehintHelper::decideTypeFromReflection($builtinMacro->getReturnType()),
76
            null,
77
            null,
78
            $builtinMacro->isDeprecated()->yes(),
79
            $builtinMacro->isInternal(),
80
            $builtinMacro->isFinal(),
81
            $supportAssertions ? null : $builtinMacro->getDocComment(),
82
            $supportAssertions ? Assertions::createEmpty() : null,
83
            null,
84
            $builtinMacro->getDocComment(),
85
            []
86
        );
87
    }
88
}