annotate vendor/psy/psysh/src/Psy/TabCompletion/Matcher/ClassNamesMatcher.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 /**
Chris@0 15 * A class name tab completion Matcher.
Chris@0 16 *
Chris@0 17 * This matcher provides completion for all declared classes.
Chris@0 18 *
Chris@0 19 * @author Marc Garcia <markcial@gmail.com>
Chris@0 20 */
Chris@0 21 class ClassNamesMatcher extends AbstractMatcher
Chris@0 22 {
Chris@0 23 /**
Chris@0 24 * {@inheritdoc}
Chris@0 25 */
Chris@0 26 public function getMatches(array $tokens, array $info = array())
Chris@0 27 {
Chris@0 28 $class = $this->getNamespaceAndClass($tokens);
Chris@0 29 if (strlen($class) > 0 && $class[0] === '\\') {
Chris@0 30 $class = substr($class, 1, strlen($class));
Chris@0 31 }
Chris@0 32 $quotedClass = preg_quote($class);
Chris@0 33
Chris@0 34 return array_map(
Chris@0 35 function ($className) use ($class) {
Chris@0 36 // get the number of namespace separators
Chris@0 37 $nsPos = substr_count($class, '\\');
Chris@0 38 $pieces = explode('\\', $className);
Chris@0 39 //$methods = Mirror::get($class);
Chris@0 40 return implode('\\', array_slice($pieces, $nsPos, count($pieces)));
Chris@0 41 },
Chris@0 42 array_filter(
Chris@0 43 get_declared_classes(),
Chris@0 44 function ($className) use ($quotedClass) {
Chris@0 45 return AbstractMatcher::startsWith($quotedClass, $className);
Chris@0 46 }
Chris@0 47 )
Chris@0 48 );
Chris@0 49 }
Chris@0 50
Chris@0 51 /**
Chris@0 52 * {@inheritdoc}
Chris@0 53 */
Chris@0 54 public function hasMatched(array $tokens)
Chris@0 55 {
Chris@12 56 $token = array_pop($tokens);
Chris@0 57 $prevToken = array_pop($tokens);
Chris@0 58
Chris@0 59 $blacklistedTokens = array(
Chris@0 60 self::T_INCLUDE, self::T_INCLUDE_ONCE, self::T_REQUIRE, self::T_REQUIRE_ONCE,
Chris@0 61 );
Chris@0 62
Chris@0 63 switch (true) {
Chris@0 64 case self::hasToken(array($blacklistedTokens), $token):
Chris@0 65 case self::hasToken(array($blacklistedTokens), $prevToken):
Chris@0 66 case is_string($token) && $token === '$':
Chris@0 67 return false;
Chris@0 68 case self::hasToken(array(self::T_NEW, self::T_OPEN_TAG, self::T_NS_SEPARATOR), $prevToken):
Chris@0 69 case self::hasToken(array(self::T_NEW, self::T_OPEN_TAG, self::T_NS_SEPARATOR), $token):
Chris@0 70 case self::hasToken(array(self::T_OPEN_TAG, self::T_VARIABLE), $token):
Chris@0 71 case self::isOperator($token):
Chris@0 72 return true;
Chris@0 73 }
Chris@0 74
Chris@0 75 return false;
Chris@0 76 }
Chris@0 77 }