Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/TabCompletion/Matcher/ClassMethodsMatcher.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
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 /** | |
15 * A class method tab completion Matcher. | |
16 * | |
17 * Given a namespace and class, this matcher provides completion for static | |
18 * methods. | |
19 * | |
20 * @author Marc Garcia <markcial@gmail.com> | |
21 */ | |
22 class ClassMethodsMatcher extends AbstractMatcher | |
23 { | |
24 /** | |
25 * {@inheritdoc} | |
26 */ | |
27 public function getMatches(array $tokens, array $info = []) | |
28 { | |
29 $input = $this->getInput($tokens); | |
30 | |
31 $firstToken = array_pop($tokens); | |
32 if (self::tokenIs($firstToken, self::T_STRING)) { | |
33 // second token is the nekudotayim operator | |
34 array_pop($tokens); | |
35 } | |
36 | |
37 $class = $this->getNamespaceAndClass($tokens); | |
38 | |
39 try { | |
40 $reflection = new \ReflectionClass($class); | |
41 } catch (\ReflectionException $re) { | |
42 return []; | |
43 } | |
44 | |
45 $methods = $reflection->getMethods(\ReflectionMethod::IS_STATIC); | |
46 $methods = array_map(function (\ReflectionMethod $method) { | |
47 return $method->getName(); | |
48 }, $methods); | |
49 | |
50 return array_map( | |
51 function ($name) use ($class) { | |
52 return $class . '::' . $name; | |
53 }, | |
54 array_filter($methods, function ($method) use ($input) { | |
55 return AbstractMatcher::startsWith($input, $method); | |
56 }) | |
57 ); | |
58 } | |
59 | |
60 /** | |
61 * {@inheritdoc} | |
62 */ | |
63 public function hasMatched(array $tokens) | |
64 { | |
65 $token = array_pop($tokens); | |
66 $prevToken = array_pop($tokens); | |
67 | |
68 switch (true) { | |
69 case self::tokenIs($prevToken, self::T_DOUBLE_COLON) && self::tokenIs($token, self::T_STRING): | |
70 case self::tokenIs($token, self::T_DOUBLE_COLON): | |
71 return true; | |
72 } | |
73 | |
74 return false; | |
75 } | |
76 } |