Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
200 lars 6
 * (c) 2012-2023 Justin Hileman
148 lars 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 Psy\TabCompletion\Matcher;
13
 
14
class ClassMethodDefaultParametersMatcher extends AbstractDefaultParametersMatcher
15
{
16
    public function getMatches(array $tokens, array $info = []): array
17
    {
18
        $openBracket = \array_pop($tokens);
19
        $functionName = \array_pop($tokens);
20
        $methodOperator = \array_pop($tokens);
21
 
22
        $class = $this->getNamespaceAndClass($tokens);
23
 
24
        try {
25
            $reflection = new \ReflectionClass($class);
26
        } catch (\ReflectionException $e) {
27
            // In this case the class apparently does not exist, so we can do nothing
28
            return [];
29
        }
30
 
31
        $methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC);
32
 
33
        foreach ($methods as $method) {
34
            if ($method->getName() === $functionName[1]) {
35
                return $this->getDefaultParameterCompletion($method->getParameters());
36
            }
37
        }
38
 
39
        return [];
40
    }
41
 
42
    public function hasMatched(array $tokens): bool
43
    {
44
        $openBracket = \array_pop($tokens);
45
 
46
        if ($openBracket !== '(') {
47
            return false;
48
        }
49
 
50
        $functionName = \array_pop($tokens);
51
 
52
        if (!self::tokenIs($functionName, self::T_STRING)) {
53
            return false;
54
        }
55
 
56
        $operator = \array_pop($tokens);
57
 
58
        if (!self::tokenIs($operator, self::T_DOUBLE_COLON)) {
59
            return false;
60
        }
61
 
62
        return true;
63
    }
64
}