69873a0f5db9102fe338c69f4077099fab7d7e72
[yaffs-website] / vendor / psy / psysh / src / Psy / TabCompletion / Matcher / ObjectMethodDefaultParametersMatcher.php
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 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 array();
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 array();
34         } catch (\ReflectionException $e) {
35             return array();
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 array();
47     }
48
49     public function hasMatched(array $tokens)
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 }