4e6025bb459ae3b047a0468b002b59bfb66dc62e
[yaffs-website] / vendor / psy / psysh / src / TabCompletion / Matcher / ClassMethodDefaultParametersMatcher.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 Justin Hileman
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 = [])
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)
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 }