comparison vendor/psy/psysh/src/Psy/TabCompletion/Matcher/ClassMethodDefaultParametersMatcher.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2017 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 = 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 array();
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 array();
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 }