annotate vendor/psy/psysh/src/Psy/TabCompletion/Matcher/ClassMethodDefaultParametersMatcher.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of Psy Shell.
Chris@0 5 *
Chris@0 6 * (c) 2012-2017 Justin Hileman
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Psy\TabCompletion\Matcher;
Chris@0 13
Chris@0 14 class ClassMethodDefaultParametersMatcher extends AbstractDefaultParametersMatcher
Chris@0 15 {
Chris@0 16 public function getMatches(array $tokens, array $info = array())
Chris@0 17 {
Chris@12 18 $openBracket = array_pop($tokens);
Chris@12 19 $functionName = array_pop($tokens);
Chris@0 20 $methodOperator = array_pop($tokens);
Chris@0 21
Chris@0 22 $class = $this->getNamespaceAndClass($tokens);
Chris@0 23
Chris@0 24 try {
Chris@0 25 $reflection = new \ReflectionClass($class);
Chris@0 26 } catch (\ReflectionException $e) {
Chris@0 27 // In this case the class apparently does not exist, so we can do nothing
Chris@0 28 return array();
Chris@0 29 }
Chris@0 30
Chris@0 31 $methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC);
Chris@0 32
Chris@0 33 foreach ($methods as $method) {
Chris@0 34 if ($method->getName() === $functionName[1]) {
Chris@0 35 return $this->getDefaultParameterCompletion($method->getParameters());
Chris@0 36 }
Chris@0 37 }
Chris@0 38
Chris@0 39 return array();
Chris@0 40 }
Chris@0 41
Chris@0 42 public function hasMatched(array $tokens)
Chris@0 43 {
Chris@0 44 $openBracket = array_pop($tokens);
Chris@0 45
Chris@0 46 if ($openBracket !== '(') {
Chris@0 47 return false;
Chris@0 48 }
Chris@0 49
Chris@0 50 $functionName = array_pop($tokens);
Chris@0 51
Chris@0 52 if (!self::tokenIs($functionName, self::T_STRING)) {
Chris@0 53 return false;
Chris@0 54 }
Chris@0 55
Chris@0 56 $operator = array_pop($tokens);
Chris@0 57
Chris@0 58 if (!self::tokenIs($operator, self::T_DOUBLE_COLON)) {
Chris@0 59 return false;
Chris@0 60 }
Chris@0 61
Chris@0 62 return true;
Chris@0 63 }
Chris@0 64 }