Skip to content

Commit 18fe522

Browse files
webflomglaman
andauthored
Upgrade to webflo/drupal-finder 1.3 (#790)
* Upgrade to webflo/drupal-finder 1.3 * Fix phpstan error * Remove realpath * Fix AccessCheckImpossibleTypeCallRuleTest * Remove drupal_root from tests * Remove drupal_root from schema * Init drupal_root with null * Add deprecation message for drupal_root * Fix docs * Update DrupalAutoloader.php * Update DrupalAutoloader.php * drop isset * remove README.md section about drupal_root --------- Co-authored-by: Matt Glaman <[email protected]>
1 parent 16dad50 commit 18fe522

File tree

5 files changed

+12
-32
lines changed

5 files changed

+12
-32
lines changed

README.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ parameters:
104104
classExtendsInternalClassRule: false
105105
```
106106

107-
### Specifying your Drupal project's root
108-
109-
By default, the PHPStan Drupal extension will try to determine your Drupal project's root directory based on the working
110-
directory that PHPStan is checking. If this is not working properly, you can explicitly define the Drupal project's root
111-
directory using the `drupal.drupal_root` parameter.
112-
113-
```
114-
parameters:
115-
drupal:
116-
drupal_root: /path/to/drupal
117-
```
118-
119-
You can also use container parameters. For instance you can always set it to the current working directory.
120-
121-
```
122-
parameters:
123-
drupal:
124-
drupal_root: %currentWorkingDirectory%
125-
```
126-
127107
### Entity storage mappings.
128108

129109
The `EntityTypeManagerGetStorageDynamicReturnTypeExtension` service helps map dynamic return types. This inspects the

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"phpstan/phpstan-deprecation-rules": "^1.1.4",
1616
"symfony/finder": "^4.2 || ^5.0 || ^6.0 || ^7.0",
1717
"symfony/yaml": "^4.2|| ^5.0 || ^6.0 || ^7.0",
18-
"webflo/drupal-finder": "^1.2"
18+
"webflo/drupal-finder": "^1.3.1"
1919
},
2020
"require-dev": {
2121
"behat/mink": "^1.8",

extension.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parameters:
1616
scanFiles:
1717
- stubs/Twig/functions.stub
1818
drupal:
19-
drupal_root: '%currentWorkingDirectory%'
19+
drupal_root: ~
2020
bleedingEdge:
2121
checkDeprecatedHooksInApiFiles: false
2222
checkCoreDeprecatedHooksInApiFiles: false
@@ -241,7 +241,7 @@ parameters:
241241

242242
parametersSchema:
243243
drupal: structure([
244-
drupal_root: string()
244+
drupal_root: schema(string(), nullable())
245245
bleedingEdge: structure([
246246
checkDeprecatedHooksInApiFiles: boolean()
247247
checkCoreDeprecatedHooksInApiFiles: boolean()

src/Drupal/DrupalAutoloader.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
77
use Drupal\Core\DrupalKernelInterface;
88
use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter;
9-
use DrupalFinder\DrupalFinder;
9+
use DrupalFinder\DrupalFinderComposerRuntime;
1010
use Drush\Drush;
1111
use PHPStan\DependencyInjection\Container;
1212
use PHPUnit\Framework\Test;
@@ -26,7 +26,6 @@
2626
use function is_array;
2727
use function is_dir;
2828
use function is_string;
29-
use function realpath;
3029
use function str_replace;
3130
use function strpos;
3231
use function strtr;
@@ -84,19 +83,21 @@ class DrupalAutoloader
8483
public function register(Container $container): void
8584
{
8685
/**
87-
* @var array{drupal_root: string, bleedingEdge: array{checkDeprecatedHooksInApiFiles: bool, checkCoreDeprecatedHooksInApiFiles: bool, checkContribDeprecatedHooksInApiFiles: bool}} $drupalParams
86+
* @var array{drupal_root: string|null, bleedingEdge: array{checkDeprecatedHooksInApiFiles: bool, checkCoreDeprecatedHooksInApiFiles: bool, checkContribDeprecatedHooksInApiFiles: bool}} $drupalParams
8887
*/
8988
$drupalParams = $container->getParameter('drupal');
90-
$drupalRoot = realpath($drupalParams['drupal_root']);
91-
$finder = new DrupalFinder();
92-
$finder->locateRoot($drupalRoot);
9389

90+
// Trigger deprecation error if drupal_root is used.
91+
if (is_string($drupalParams['drupal_root'])) {
92+
trigger_error('The drupal_root parameter is deprecated. Remove it from your configuration. Drupal Root is discoverd automatically.', E_USER_DEPRECATED);
93+
}
94+
95+
$finder = new DrupalFinderComposerRuntime();
9496
$drupalRoot = $finder->getDrupalRoot();
9597
$drupalVendorRoot = $finder->getVendorDir();
9698
if (!(is_string($drupalRoot) && is_string($drupalVendorRoot))) {
97-
throw new RuntimeException("Unable to detect Drupal at {$drupalParams['drupal_root']}");
99+
throw new RuntimeException("Unable to detect Drupal with webflo/drupal-finder.");
98100
}
99-
100101
$this->drupalRoot = $drupalRoot;
101102

102103
$this->autoloader = include $drupalVendorRoot . '/autoload.php';

tests/fixtures/config/phpunit-drupal-phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
parameters:
22
drupal:
3-
drupal_root: tests/fixtures/drupal
43
entityMapping:
54
content_entity_using_custom_storage:
65
class: Drupal\phpstan_fixtures\Entity\ContentEntityUsingCustomStorage

0 commit comments

Comments
 (0)