Skip to content

Commit

Permalink
DQA-10557: Ensure project using phpstan/extension-installer (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisSantosEncinas authored Nov 25, 2024
1 parent 8c16a67 commit 3cf2366
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/runner/toolkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ toolkit:
- 'DrupalComposer\DrupalScaffold\Plugin::scaffold'
configuration:
validations:
- message: 'When using phpstan/extension-installer you should not manually include the extensions in the phpstan.neon file, please remove the includes.'
- message: 'When using phpstan/extension-installer you should not manually include the extensions in the phpstan.neon file, please remove the includes, otherwise ensure the includes section is properly set.'
callback: 'EcEuropa\Toolkit\Callbacks\ConfigurationCallbacks::validatePhpStan'
blocker: true
- message: "The .env file was detected!\n In order to avoid loading .env file in ACC or PROD environments, please rename it to something like .env.dist\n The file belongs to your application. You should guarantee that is not being called into any point of your Drupal site. If you are only calling it in docker-compose.yml, it's recommended to drop entirely the file and declare the environment variables straight into docker-compose.yml file."
Expand Down
17 changes: 12 additions & 5 deletions src/Callbacks/ConfigurationCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ public static function validateGrumPhp(): bool
}

/**
* If project is using phpstan/extension-installer then should not manually include extensions.
* Validate when using phpstan/extension-installer the include should not be used, otherwise, include is required.
*/
public static function validatePhpStan(): bool
{
$file = 'phpstan.neon';
// Stop if the config file do not exist or the package is not installed.
if (!file_exists($file) || !ToolCommands::isPackageInstalled('phpstan/extension-installer')) {

// Skip if the project does not have the config file.
if (!file_exists($file)) {
return true;
}
// Load the config file and check for the includes.

$config = Yaml::parseFile($file);
return empty($config['includes']);
// If project is using phpstan/extension-installer then should not manually include extensions.
if (ToolCommands::isPackageInstalled('phpstan/extension-installer')) {
return empty($config['includes']);
}

// If project is not using phpstan/extension-installer then should manually include extensions.
return !empty($config['includes']);
}

}
32 changes: 32 additions & 0 deletions tests/fixtures/commands/component-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,38 @@
expectations:
- string_contains: When using phpstan/extension-installer you should not manually include

- command: 'toolkit:component-check'
configuration: []
tokens: ''
resources:
- touch: composer.json
- file: composer.lock
content: |
{ "packages": [] }
- file: phpstan.neon
content: |
parameters:
level: 5
expectations:
- string_contains: When using phpstan/extension-installer you should not manually include

- command: 'toolkit:component-check'
configuration: []
tokens: ''
resources:
- touch: composer.json
- file: composer.lock
content: |
{ "packages": [
{ "name": "phpstan/extension-installer", "type": "composer-plugin", "version": "1.2.0" }
] }
- file: phpstan.neon
content: |
parameters:
level: 5
expectations:
- not_string_contains: When using phpstan/extension-installer you should not manually include

- command: 'toolkit:component-check'
configuration: []
tokens: ''
Expand Down

0 comments on commit 3cf2366

Please sign in to comment.