Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/TabCompletion/Matcher/AbstractMatcher.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
62 * @return string | 62 * @return string |
63 */ | 63 */ |
64 protected function getInput(array $tokens) | 64 protected function getInput(array $tokens) |
65 { | 65 { |
66 $var = ''; | 66 $var = ''; |
67 $firstToken = array_pop($tokens); | 67 $firstToken = \array_pop($tokens); |
68 if (self::tokenIs($firstToken, self::T_STRING)) { | 68 if (self::tokenIs($firstToken, self::T_STRING)) { |
69 $var = $firstToken[1]; | 69 $var = $firstToken[1]; |
70 } | 70 } |
71 | 71 |
72 return $var; | 72 return $var; |
82 protected function getNamespaceAndClass($tokens) | 82 protected function getNamespaceAndClass($tokens) |
83 { | 83 { |
84 $class = ''; | 84 $class = ''; |
85 while (self::hasToken( | 85 while (self::hasToken( |
86 [self::T_NS_SEPARATOR, self::T_STRING], | 86 [self::T_NS_SEPARATOR, self::T_STRING], |
87 $token = array_pop($tokens) | 87 $token = \array_pop($tokens) |
88 )) { | 88 )) { |
89 if (self::needCompleteClass($token)) { | 89 if (self::needCompleteClass($token)) { |
90 continue; | 90 continue; |
91 } | 91 } |
92 | 92 |
114 * | 114 * |
115 * @return bool | 115 * @return bool |
116 */ | 116 */ |
117 public static function startsWith($prefix, $word) | 117 public static function startsWith($prefix, $word) |
118 { | 118 { |
119 return preg_match(sprintf('#^%s#', $prefix), $word); | 119 return \preg_match(\sprintf('#^%s#', $prefix), $word); |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Check whether $token matches a given syntax pattern. | 123 * Check whether $token matches a given syntax pattern. |
124 * | 124 * |
127 * | 127 * |
128 * @return bool | 128 * @return bool |
129 */ | 129 */ |
130 public static function hasSyntax($token, $syntax = self::VAR_SYNTAX) | 130 public static function hasSyntax($token, $syntax = self::VAR_SYNTAX) |
131 { | 131 { |
132 if (!is_array($token)) { | 132 if (!\is_array($token)) { |
133 return false; | 133 return false; |
134 } | 134 } |
135 | 135 |
136 $regexp = sprintf('#%s#', $syntax); | 136 $regexp = \sprintf('#%s#', $syntax); |
137 | 137 |
138 return (bool) preg_match($regexp, $token[1]); | 138 return (bool) \preg_match($regexp, $token[1]); |
139 } | 139 } |
140 | 140 |
141 /** | 141 /** |
142 * Check whether $token type is $which. | 142 * Check whether $token type is $which. |
143 * | 143 * |
146 * | 146 * |
147 * @return bool | 147 * @return bool |
148 */ | 148 */ |
149 public static function tokenIs($token, $which) | 149 public static function tokenIs($token, $which) |
150 { | 150 { |
151 if (!is_array($token)) { | 151 if (!\is_array($token)) { |
152 return false; | 152 return false; |
153 } | 153 } |
154 | 154 |
155 return token_name($token[0]) === $which; | 155 return \token_name($token[0]) === $which; |
156 } | 156 } |
157 | 157 |
158 /** | 158 /** |
159 * Check whether $token is an operator. | 159 * Check whether $token is an operator. |
160 * | 160 * |
162 * | 162 * |
163 * @return bool | 163 * @return bool |
164 */ | 164 */ |
165 public static function isOperator($token) | 165 public static function isOperator($token) |
166 { | 166 { |
167 if (!is_string($token)) { | 167 if (!\is_string($token)) { |
168 return false; | 168 return false; |
169 } | 169 } |
170 | 170 |
171 return strpos(self::MISC_OPERATORS, $token) !== false; | 171 return \strpos(self::MISC_OPERATORS, $token) !== false; |
172 } | 172 } |
173 | 173 |
174 public static function needCompleteClass($token) | 174 public static function needCompleteClass($token) |
175 { | 175 { |
176 return in_array($token[1], ['doc', 'ls', 'show']); | 176 return \in_array($token[1], ['doc', 'ls', 'show']); |
177 } | 177 } |
178 | 178 |
179 /** | 179 /** |
180 * Check whether $token type is present in $coll. | 180 * Check whether $token type is present in $coll. |
181 * | 181 * |
184 * | 184 * |
185 * @return bool | 185 * @return bool |
186 */ | 186 */ |
187 public static function hasToken(array $coll, $token) | 187 public static function hasToken(array $coll, $token) |
188 { | 188 { |
189 if (!is_array($token)) { | 189 if (!\is_array($token)) { |
190 return false; | 190 return false; |
191 } | 191 } |
192 | 192 |
193 return in_array(token_name($token[0]), $coll); | 193 return \in_array(\token_name($token[0]), $coll); |
194 } | 194 } |
195 } | 195 } |