2
2
3
3
namespace PHPStan \DependencyInjection ;
4
4
5
+ use DrupalFinder \DrupalFinder ;
5
6
use Nette \DI \CompilerExtension ;
6
7
use Nette \DI \Config \Helpers ;
7
8
use PHPStan \Drupal \ExtensionDiscovery ;
@@ -19,11 +20,6 @@ class DrupalExtension extends CompilerExtension
19
20
'themes ' => [],
20
21
];
21
22
22
- /**
23
- * @var string
24
- */
25
- private $ autoloaderPath ;
26
-
27
23
/**
28
24
* @var string
29
25
*/
@@ -55,24 +51,9 @@ class DrupalExtension extends CompilerExtension
55
51
56
52
public function loadConfiguration (): void
57
53
{
58
-
59
- $ this ->autoloaderPath = $ GLOBALS ['autoloaderInWorkingDirectory ' ];
60
- $ realpath = realpath ($ this ->autoloaderPath );
61
- if ($ realpath === false ) {
62
- throw new \InvalidArgumentException ('Cannot determine the realpath of the autoloader. ' );
63
- }
64
- $ project_root = dirname ($ realpath , 2 );
65
- if (is_dir ($ project_root . '/core ' )) {
66
- $ this ->drupalRoot = $ project_root ;
67
- }
68
- foreach (['web ' , 'docroot ' ] as $ possible_docroot ) {
69
- if (is_dir ("$ project_root/ $ possible_docroot/core " )) {
70
- $ this ->drupalRoot = "$ project_root/ $ possible_docroot " ;
71
- }
72
- }
73
- if ($ this ->drupalRoot === null ) {
74
- throw new \InvalidArgumentException ('Unable to determine the Drupal root ' );
75
- }
54
+ $ finder = new DrupalFinder ();
55
+ $ finder ->locateRoot (getcwd ());
56
+ $ this ->drupalRoot = $ finder ->getDrupalRoot ();
76
57
77
58
$ builder = $ this ->getContainerBuilder ();
78
59
$ builder ->parameters ['drupalRoot ' ] = $ this ->drupalRoot ;
@@ -99,7 +80,7 @@ public function loadConfiguration(): void
99
80
$ extensionDiscovery = new ExtensionDiscovery ($ this ->drupalRoot );
100
81
$ extensionDiscovery ->setProfileDirectories ([]);
101
82
$ profiles = $ extensionDiscovery ->scan ('profile ' );
102
- $ profile_directories = array_map (function ($ profile ) {
83
+ $ profile_directories = array_map (function (\ PHPStan \ Drupal \ Extension $ profile ) : string {
103
84
return $ profile ->getPath ();
104
85
}, $ profiles );
105
86
$ extensionDiscovery ->setProfileDirectories ($ profile_directories );
@@ -139,8 +120,13 @@ public function loadConfiguration(): void
139
120
// Prevent \Nette\DI\ContainerBuilder::completeStatement from array_walk_recursive into the arguments
140
121
// and thinking these are real services for PHPStan's container.
141
122
if (isset ($ serviceDefinition ['arguments ' ]) && is_array ($ serviceDefinition ['arguments ' ])) {
142
- array_walk ($ serviceDefinition ['arguments ' ], function (&$ argument ) {
143
- $ argument = str_replace ('@ ' , '' , $ argument );
123
+ array_walk ($ serviceDefinition ['arguments ' ], function (&$ argument ) : void {
124
+ if (is_array ($ argument )) {
125
+ // @todo fix for @http_kernel.controller.argument_metadata_factory
126
+ $ argument = '' ;
127
+ } else {
128
+ $ argument = str_replace ('@ ' , '' , $ argument );
129
+ }
144
130
});
145
131
}
146
132
unset($ serviceDefinition ['tags ' ]);
0 commit comments