Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from SebSept/auto_config_phpstan
Browse files Browse the repository at this point in the history
auto detect _PS_ROOT_DIR_ on phpstan init
  • Loading branch information
SebSept authored May 18, 2021
2 parents ee69261 + cffea5e commit e5eef75
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ There's a couple options available, [this one](https://github.com/bamarni/symfon
## Featured tools

- Code formating : [php-cs-fixer](https://github.com/FriendsOfPhp/PHP-CS-Fixer) configured using prestashop standard, ready to use out of the box.
- Code analysis : [phpstan](https://phpstan.org/) almost ready to use with Prestashop standard, it asks a question then you're ready.
- Code analysis : [phpstan](https://phpstan.org/) autodetect PrestaShop root directory or asks (nothing more to do).
- `fill-indexes` command, to add required index.php files. (see below for details)
- git pre-commit hook installer (details below)

Expand Down Expand Up @@ -65,16 +65,19 @@ Allows complying with the [Prestashop standards](https://devdocs.prestashop.com/

`composer psdt:phpstan [--reconfigure]`

Run Phpstan from prestashop/prestashop-dev-tools.
Run phpstan configured with [Prestashop standards](https://devdocs.prestashop.com/1.7/development/coding-standards/) against a PrestaShop installation.

Just like psdt:php-cs-fixer, the first run install the package and creates/overrides the phpstan.neon configuration with Prestashop standards.
The first run or `composer psdt:phpstan --reconfigure` do :
- install `prestashop/prestashop-dev-tools` if needed
- creates/overrides the phpstan.neon configuration with Prestashop standards.
- guess the \_PS_ROOT_DIR_ and asks for confirmation (or you can provide another path) (this path is needed for analyse)
- install a composer script `phpstan`

The next runs will trigger `composer psdt:phpstan`

Provided by [PrestaShop/php-dev-tools/](https://github.com/PrestaShop/php-dev-tools/).
Autoinstallation provided by this package.

Allows complying with the [Prestashop standards](https://devdocs.prestashop.com/1.7/development/coding-standards/).


### fill-indexes

`composer psdt:fill-indexes`
Expand Down
30 changes: 21 additions & 9 deletions src/Command/PrestashopDevTools/PrestashopDevToolsPhpStan.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected function configure(): void

/**
* Is Tool configurated ?
*
* Tool is considered configured if
* - phpstan.neon exists
* - "phpstan" composer script exists.
Expand All @@ -85,8 +84,17 @@ public function isToolConfigured(): bool
*/
public function configureTool(): void
{
// ----- add phpstan.neon
$this->copyPhpStanNeonFile();
$this->askPrestashopPathAndAddComposerScripts();
}

public function getComposerScriptName(): string
{
return 'phpstan';
}

private function copyPhpStanNeonFile(): void
{
// first, delete the file, otherwise the installation process does not write the new file.
// https://github.com/PrestaShop/php-dev-tools/issues/58
// that's a bit touchy, it relies on the fact the file name won't change. Otherwise our workaround will fail.
Expand All @@ -113,17 +121,21 @@ public function configureTool(): void
$this->getIO()->write('<bg=green>successful</bg=green>');
$this->getIO()->info(' in fact, it\'s only PROBABLY successfull.');
$this->getIO()->info(' https://github.com/PrestaShop/php-dev-tools/issues/58');
}

// ------ add composer script
/**
* @throws \Seld\JsonLint\ParsingException
*/
private function askPrestashopPathAndAddComposerScripts(): void
{
$this->getIO()->write('To perform code analyse, phpstan needs a path to a Prestashop installation.');
$prestashopPath = $this->getIO()->ask('What is the path to is this Prestashop installation ? ');
$guessedPsRoot = realpath(getcwd() . '/../../') ?: '';
$prestashopPath = $this->getIO()->ask(
sprintf('What is the path to is this Prestashop installation %s ? ', '(leave blank to use <comment>' . $guessedPsRoot . '</comment>)'),
$guessedPsRoot
);
$this->addComposerScript([
"@putenv _PS_ROOT_DIR_=$prestashopPath",
'phpstan analyse', ]);
}

public function getComposerScriptName(): string
{
return 'phpstan';
}
}

0 comments on commit e5eef75

Please sign in to comment.