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 ObjectMethodDefaultParametersMatcher 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
        $objectToken = \array_pop($tokens);
23
        if (!\is_array($objectToken)) {
24
            return [];
25
        }
26
 
27
        $objectName = \str_replace('$', '', $objectToken[1]);
28
 
29
        try {
30
            $object = $this->getVariable($objectName);
31
            $reflection = new \ReflectionObject($object);
32
        } catch (\InvalidArgumentException $e) {
33
            return [];
34
        } catch (\ReflectionException $e) {
35
            return [];
36
        }
37
 
38
        $methods = $reflection->getMethods();
39
 
40
        foreach ($methods as $method) {
41
            if ($method->getName() === $functionName[1]) {
42
                return $this->getDefaultParameterCompletion($method->getParameters());
43
            }
44
        }
45
 
46
        return [];
47
    }
48
 
49
    public function hasMatched(array $tokens): bool
50
    {
51
        $openBracket = \array_pop($tokens);
52
 
53
        if ($openBracket !== '(') {
54
            return false;
55
        }
56
 
57
        $functionName = \array_pop($tokens);
58
 
59
        if (!self::tokenIs($functionName, self::T_STRING)) {
60
            return false;
61
        }
62
 
63
        $operator = \array_pop($tokens);
64
 
65
        if (!self::tokenIs($operator, self::T_OBJECT_OPERATOR)) {
66
            return false;
67
        }
68
 
69
        return true;
70
    }
71
}