Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/src/CodeCleaner/ValidClassNamePass.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
36 { | 36 { |
37 const CLASS_TYPE = 'class'; | 37 const CLASS_TYPE = 'class'; |
38 const INTERFACE_TYPE = 'interface'; | 38 const INTERFACE_TYPE = 'interface'; |
39 const TRAIT_TYPE = 'trait'; | 39 const TRAIT_TYPE = 'trait'; |
40 | 40 |
41 protected $checkTraits; | |
42 private $conditionalScopes = 0; | 41 private $conditionalScopes = 0; |
43 private $atLeastPhp55; | 42 private $atLeastPhp55; |
44 | 43 |
45 public function __construct() | 44 public function __construct() |
46 { | 45 { |
47 $this->checkTraits = function_exists('trait_exists'); | |
48 $this->atLeastPhp55 = version_compare(PHP_VERSION, '5.5', '>='); | 46 $this->atLeastPhp55 = version_compare(PHP_VERSION, '5.5', '>='); |
49 } | 47 } |
50 | 48 |
51 /** | 49 /** |
52 * Validate class, interface and trait definitions. | 50 * Validate class, interface and trait definitions. |
115 * | 113 * |
116 * @param Class_ $stmt | 114 * @param Class_ $stmt |
117 */ | 115 */ |
118 protected function validateClassStatement(Class_ $stmt) | 116 protected function validateClassStatement(Class_ $stmt) |
119 { | 117 { |
120 $this->ensureCanDefine($stmt); | 118 $this->ensureCanDefine($stmt, self::CLASS_TYPE); |
121 if (isset($stmt->extends)) { | 119 if (isset($stmt->extends)) { |
122 $this->ensureClassExists($this->getFullyQualifiedName($stmt->extends), $stmt); | 120 $this->ensureClassExists($this->getFullyQualifiedName($stmt->extends), $stmt); |
123 } | 121 } |
124 $this->ensureInterfacesExist($stmt->implements, $stmt); | 122 $this->ensureInterfacesExist($stmt->implements, $stmt); |
125 } | 123 } |
129 * | 127 * |
130 * @param Interface_ $stmt | 128 * @param Interface_ $stmt |
131 */ | 129 */ |
132 protected function validateInterfaceStatement(Interface_ $stmt) | 130 protected function validateInterfaceStatement(Interface_ $stmt) |
133 { | 131 { |
134 $this->ensureCanDefine($stmt); | 132 $this->ensureCanDefine($stmt, self::INTERFACE_TYPE); |
135 $this->ensureInterfacesExist($stmt->extends, $stmt); | 133 $this->ensureInterfacesExist($stmt->extends, $stmt); |
136 } | 134 } |
137 | 135 |
138 /** | 136 /** |
139 * Validate a trait definition statement. | 137 * Validate a trait definition statement. |
140 * | 138 * |
141 * @param Trait_ $stmt | 139 * @param Trait_ $stmt |
142 */ | 140 */ |
143 protected function validateTraitStatement(Trait_ $stmt) | 141 protected function validateTraitStatement(Trait_ $stmt) |
144 { | 142 { |
145 $this->ensureCanDefine($stmt); | 143 $this->ensureCanDefine($stmt, self::TRAIT_TYPE); |
146 } | 144 } |
147 | 145 |
148 /** | 146 /** |
149 * Validate a `new` expression. | 147 * Validate a `new` expression. |
150 * | 148 * |
192 /** | 190 /** |
193 * Ensure that no class, interface or trait name collides with a new definition. | 191 * Ensure that no class, interface or trait name collides with a new definition. |
194 * | 192 * |
195 * @throws FatalErrorException | 193 * @throws FatalErrorException |
196 * | 194 * |
197 * @param Stmt $stmt | 195 * @param Stmt $stmt |
198 */ | 196 * @param string $scopeType |
199 protected function ensureCanDefine(Stmt $stmt) | 197 */ |
198 protected function ensureCanDefine(Stmt $stmt, $scopeType = self::CLASS_TYPE) | |
200 { | 199 { |
201 $name = $this->getFullyQualifiedName($stmt->name); | 200 $name = $this->getFullyQualifiedName($stmt->name); |
202 | 201 |
203 // check for name collisions | 202 // check for name collisions |
204 $errorType = null; | 203 $errorType = null; |
214 throw $this->createError(sprintf('%s named %s already exists', ucfirst($errorType), $name), $stmt); | 213 throw $this->createError(sprintf('%s named %s already exists', ucfirst($errorType), $name), $stmt); |
215 } | 214 } |
216 | 215 |
217 // Store creation for the rest of this code snippet so we can find local | 216 // Store creation for the rest of this code snippet so we can find local |
218 // issue too | 217 // issue too |
219 $this->currentScope[strtolower($name)] = $this->getScopeType($stmt); | 218 $this->currentScope[strtolower($name)] = $scopeType; |
220 } | 219 } |
221 | 220 |
222 /** | 221 /** |
223 * Ensure that a referenced class exists. | 222 * Ensure that a referenced class exists. |
224 * | 223 * |
302 } | 301 } |
303 | 302 |
304 /** | 303 /** |
305 * Get a symbol type key for storing in the scope name cache. | 304 * Get a symbol type key for storing in the scope name cache. |
306 * | 305 * |
306 * @deprecated No longer used. Scope type should be passed into ensureCanDefine directly. | |
307 * @codeCoverageIgnore | |
308 * | |
307 * @param Stmt $stmt | 309 * @param Stmt $stmt |
308 * | 310 * |
309 * @return string | 311 * @return string |
310 */ | 312 */ |
311 protected function getScopeType(Stmt $stmt) | 313 protected function getScopeType(Stmt $stmt) |
359 * | 361 * |
360 * @return bool | 362 * @return bool |
361 */ | 363 */ |
362 protected function traitExists($name) | 364 protected function traitExists($name) |
363 { | 365 { |
364 return $this->checkTraits && (trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE); | 366 return trait_exists($name) || $this->findInScope($name) === self::TRAIT_TYPE; |
365 } | 367 } |
366 | 368 |
367 /** | 369 /** |
368 * Find a symbol in the current code snippet scope. | 370 * Find a symbol in the current code snippet scope. |
369 * | 371 * |