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

Commit e5eef75

Browse files
authored
Merge pull request #26 from SebSept/auto_config_phpstan
auto detect _PS_ROOT_DIR_ on phpstan init
2 parents ee69261 + cffea5e commit e5eef75

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ There's a couple options available, [this one](https://github.com/bamarni/symfon
2020
## Featured tools
2121

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

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

6666
`composer psdt:phpstan [--reconfigure]`
6767

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

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

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

75-
Allows complying with the [Prestashop standards](https://devdocs.prestashop.com/1.7/development/coding-standards/).
76-
77-
7881
### fill-indexes
7982

8083
`composer psdt:fill-indexes`

src/Command/PrestashopDevTools/PrestashopDevToolsPhpStan.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ protected function configure(): void
6262

6363
/**
6464
* Is Tool configurated ?
65-
*
6665
* Tool is considered configured if
6766
* - phpstan.neon exists
6867
* - "phpstan" composer script exists.
@@ -85,8 +84,17 @@ public function isToolConfigured(): bool
8584
*/
8685
public function configureTool(): void
8786
{
88-
// ----- add phpstan.neon
87+
$this->copyPhpStanNeonFile();
88+
$this->askPrestashopPathAndAddComposerScripts();
89+
}
8990

91+
public function getComposerScriptName(): string
92+
{
93+
return 'phpstan';
94+
}
95+
96+
private function copyPhpStanNeonFile(): void
97+
{
9098
// first, delete the file, otherwise the installation process does not write the new file.
9199
// https://github.com/PrestaShop/php-dev-tools/issues/58
92100
// that's a bit touchy, it relies on the fact the file name won't change. Otherwise our workaround will fail.
@@ -113,17 +121,21 @@ public function configureTool(): void
113121
$this->getIO()->write('<bg=green>successful</bg=green>');
114122
$this->getIO()->info(' in fact, it\'s only PROBABLY successfull.');
115123
$this->getIO()->info(' https://github.com/PrestaShop/php-dev-tools/issues/58');
124+
}
116125

117-
// ------ add composer script
126+
/**
127+
* @throws \Seld\JsonLint\ParsingException
128+
*/
129+
private function askPrestashopPathAndAddComposerScripts(): void
130+
{
118131
$this->getIO()->write('To perform code analyse, phpstan needs a path to a Prestashop installation.');
119-
$prestashopPath = $this->getIO()->ask('What is the path to is this Prestashop installation ? ');
132+
$guessedPsRoot = realpath(getcwd() . '/../../') ?: '';
133+
$prestashopPath = $this->getIO()->ask(
134+
sprintf('What is the path to is this Prestashop installation %s ? ', '(leave blank to use <comment>' . $guessedPsRoot . '</comment>)'),
135+
$guessedPsRoot
136+
);
120137
$this->addComposerScript([
121138
"@putenv _PS_ROOT_DIR_=$prestashopPath",
122139
'phpstan analyse', ]);
123140
}
124-
125-
public function getComposerScriptName(): string
126-
{
127-
return 'phpstan';
128-
}
129141
}

0 commit comments

Comments
 (0)