3
3
namespace mglaman \PHPStanDrupal \Drupal ;
4
4
5
5
use Drupal \Core \DependencyInjection \ContainerNotInitializedException ;
6
+ use Drupal \TestTools \PhpUnitCompatibility \PhpUnit8 \ClassWriter ;
6
7
use DrupalFinder \DrupalFinder ;
8
+ use Drush \Drush ;
7
9
use PHPStan \DependencyInjection \Container ;
10
+ use PHPUnit \Framework \Test ;
11
+ use ReflectionClass ;
12
+ use RuntimeException ;
8
13
use Symfony \Component \Finder \Finder ;
9
14
use Symfony \Component \Yaml \Yaml ;
15
+ use Throwable ;
16
+ use function array_map ;
17
+ use function array_merge ;
18
+ use function array_walk ;
19
+ use function class_exists ;
20
+ use function dirname ;
21
+ use function file_exists ;
22
+ use function in_array ;
23
+ use function interface_exists ;
24
+ use function is_array ;
25
+ use function is_dir ;
26
+ use function is_string ;
27
+ use function realpath ;
28
+ use function str_replace ;
29
+ use function strpos ;
30
+ use function strtr ;
31
+ use function trigger_error ;
32
+ use function ucwords ;
33
+ use function usort ;
10
34
11
35
class DrupalAutoloader
12
36
{
@@ -68,7 +92,7 @@ public function register(Container $container): void
68
92
$ drupalRoot = $ finder ->getDrupalRoot ();
69
93
$ drupalVendorRoot = $ finder ->getVendorDir ();
70
94
if (! (bool ) $ drupalRoot || ! (bool ) $ drupalVendorRoot ) {
71
- throw new \ RuntimeException ("Unable to detect Drupal at {$ drupalParams ['drupal_root ' ]}" );
95
+ throw new RuntimeException ("Unable to detect Drupal at {$ drupalParams ['drupal_root ' ]}" );
72
96
}
73
97
74
98
$ this ->drupalRoot = $ drupalRoot ;
@@ -142,11 +166,11 @@ public function register(Container $container): void
142
166
}
143
167
}
144
168
145
- if (class_exists (\ Drush \ Drush::class)) {
146
- $ reflect = new \ ReflectionClass (\ Drush \ Drush::class);
169
+ if (class_exists (Drush::class)) {
170
+ $ reflect = new ReflectionClass (Drush::class);
147
171
if ($ reflect ->getFileName () !== false ) {
148
172
$ levels = 2 ;
149
- if (\ Drush \ Drush::getMajorVersion () < 9 ) {
173
+ if (Drush::getMajorVersion () < 9 ) {
150
174
$ levels = 3 ;
151
175
}
152
176
$ drushDir = dirname ($ reflect ->getFileName (), $ levels );
@@ -200,9 +224,9 @@ class: Drupal\jsonapi\Routing\JsonApiParamEnhancer
200
224
$ service_map = $ container ->getByType (ServiceMap::class);
201
225
$ service_map ->setDrupalServices ($ this ->serviceMap );
202
226
203
- if (interface_exists (\ PHPUnit \ Framework \ Test::class)
227
+ if (interface_exists (Test::class)
204
228
&& class_exists ('Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter ' )) {
205
- \ Drupal \ TestTools \ PhpUnitCompatibility \ PhpUnit8 \ ClassWriter::mutateTestBase ($ this ->autoloader );
229
+ ClassWriter::mutateTestBase ($ this ->autoloader );
206
230
}
207
231
208
232
$ extension_map = $ container ->getByType (ExtensionMap::class);
@@ -307,7 +331,7 @@ protected function loadExtension(Extension $extension): void
307
331
{
308
332
try {
309
333
$ extension ->load ();
310
- } catch (\ Throwable $ e ) {
334
+ } catch (Throwable $ e ) {
311
335
// Something prevented the extension file from loading.
312
336
// This can happen when drupal_get_path or drupal_get_filename are used outside of the scope of a function.
313
337
}
@@ -321,7 +345,7 @@ protected function loadAndCatchErrors(string $path): void
321
345
$ path = str_replace (dirname ($ this ->drupalRoot ) . '/ ' , '' , $ path );
322
346
// This can happen when drupal_get_path or drupal_get_filename are used outside the scope of a function.
323
347
@trigger_error ("$ path invoked the Drupal container outside of the scope of a function or class method. It was not loaded. " , E_USER_WARNING );
324
- } catch (\ Throwable $ e ) {
348
+ } catch (Throwable $ e ) {
325
349
$ path = str_replace (dirname ($ this ->drupalRoot ) . '/ ' , '' , $ path );
326
350
// Something prevented the extension file from loading.
327
351
@trigger_error ("$ path failed loading due to {$ e ->getMessage ()}" , E_USER_WARNING );
0 commit comments