Skip to content

Commit 0f1be7a

Browse files
authored
Merge pull request #318 from boesing/feature/phpstan
PHPStan tooling detection
2 parents ba2409e + 6fcdd55 commit 0f1be7a

26 files changed

+184
-91
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Currently, it identifies the following:
2626
- PHPUnit tests based on the presence of `phpunit.xml.dist` or `phpunit.xml` files.
2727
- phpcs checks based on the presence of `phpcs.xml.dist` or `phpcs.xml` files.
2828
- Psalm checks based on the presence of `psalm.xml.dist` or `psalm.xml` files.
29+
- PHPStan checks based on the presence of `phpstan.neon`, `phpstan.neon.dist` or `phpstan.dist.neon` files.
2930
- ComposerRequireChecker checks based on the presence of `composer-require-checker.json` file.
3031
- phpbench benchmarks based on the presence of a `phpbench.json`.
3132
- Infection mutation tests based on the presence of `infection.json` or `infection.json.dist`. In case that `roave/infection-static-analysis-plugin` is installed, this will be used instead.

src/config/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import fs, {PathLike} from 'fs';
22
import semver from 'semver';
33
import parseJsonFile from '../json';
4-
import {isToolRunningContainerDefaultPhpVersion, Tool, ToolExecutionType} from '../tools';
4+
import {isToolRunningContainerDefaultPhpVersion, Tool} from '../tools';
55
import {Logger} from '../logging';
6+
import {ToolExecutionType} from '../enum/toolExecutionType';
67
import {
78
CONTAINER_DEFAULT_PHP_VERSION,
89
CURRENT_STABLE,

src/enum/toolExecutionType.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export enum ToolExecutionType {
2+
/**
3+
* @description Executed on every supported PHP version with lowest & latest dependencies.
4+
* In case, a lock-file is present, the minimum supported PHP version will also run with LOCKED
5+
* dependencies.
6+
*/
7+
MATRIX = 'matrix',
8+
9+
/**
10+
* @description Executed on the minimum PHP version with either LOCKED or LATEST dependencies.
11+
*/
12+
STATIC = 'static',
13+
}

src/enum/toolType.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum ToolType {
2+
LINTER = 'linter',
3+
CODE_CHECK = 'code_check',
4+
}

src/tools.ts

Lines changed: 20 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
import fs, {PathLike} from 'fs';
22
import {Config} from './config/app';
3-
import {ComposerJson} from './config/composer';
4-
import parseJsonFile from './json';
53
import {CONTAINER_DEFAULT_PHP_VERSION} from './config/php';
6-
7-
export enum ToolExecutionType {
8-
/**
9-
* @description Executed on every supported PHP version with lowest & latest dependencies.
10-
* In case, a lock-file is present, the minimum supported PHP version will also run with LOCKED
11-
* dependencies.
12-
*/
13-
MATRIX = 'matrix',
14-
15-
/**
16-
* @description Executed on the minimum PHP version with either LOCKED or LATEST dependencies.
17-
*/
18-
STATIC = 'static',
19-
}
20-
21-
enum ToolType {
22-
LINTER = 'linter',
23-
CODE_CHECK = 'code_check',
24-
}
4+
import {PHPUnitTool} from './tools/phpunit';
5+
import {InfectionTool} from './tools/infection';
6+
import {PhpCodeSnifferTool} from './tools/codesniffer';
7+
import {PsalmTool} from './tools/psalm';
8+
import {ComposerRequireCheckerTool} from './tools/composerRequireChecker';
9+
import {PhpBenchTool} from './tools/phpbench';
10+
import {CodeceptionTool} from './tools/codeception';
11+
import {PhpCsFixerTool} from './tools/phpCsFixer';
12+
import {PHPStanTool} from './tools/phpstan';
13+
import {ToolExecutionType} from './enum/toolExecutionType';
14+
import {ToolType} from './enum/toolType';
2515

2616
export type Tool = {
2717
executionType: ToolExecutionType,
@@ -36,16 +26,6 @@ export type ToolRunningContainerDefaultPhpVersion = Tool & {
3626
php: typeof CONTAINER_DEFAULT_PHP_VERSION,
3727
}
3828

39-
function detectInfectionCommand(): string {
40-
const composerJson: ComposerJson = parseJsonFile('composer.json', true) as ComposerJson;
41-
42-
if (composerJson['require-dev']?.['roave/infection-static-analysis-plugin'] !== undefined) {
43-
return 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin';
44-
}
45-
46-
return 'phpdbg -qrr ./vendor/bin/infection';
47-
}
48-
4929
function backwardCompatibilityCheckTool(config: Config): ToolRunningContainerDefaultPhpVersion | null {
5030
if (!config.backwardCompatibilityCheck) {
5131
return null;
@@ -95,65 +75,15 @@ export default function createTools(config: Config): Array<Tool> {
9575
filesToCheck : [ 'README.md' ],
9676
toolType : ToolType.LINTER,
9777
},
98-
{
99-
executionType : ToolExecutionType.MATRIX,
100-
name : 'PHPUnit',
101-
command : './vendor/bin/phpunit',
102-
filesToCheck : [ 'phpunit.xml.dist', 'phpunit.xml' ],
103-
toolType : ToolType.CODE_CHECK,
104-
lintConfigCommand : 'xmllint --schema vendor/phpunit/phpunit/phpunit.xsd',
105-
},
106-
{
107-
executionType : ToolExecutionType.STATIC,
108-
name : 'Infection',
109-
command : detectInfectionCommand(),
110-
filesToCheck : [ 'infection.json', 'infection.json.dist' ],
111-
toolType : ToolType.CODE_CHECK,
112-
},
113-
{
114-
executionType : ToolExecutionType.STATIC,
115-
name : 'PHPCodeSniffer',
116-
command : './vendor/bin/phpcs -q --report=checkstyle | cs2pr',
117-
filesToCheck : [ 'phpcs.xml', 'phpcs.xml.dist' ],
118-
toolType : ToolType.CODE_CHECK,
119-
lintConfigCommand : 'xmllint --schema vendor/squizlabs/php_codesniffer/phpcs.xsd',
120-
},
121-
{
122-
executionType : ToolExecutionType.STATIC,
123-
name : 'Psalm',
124-
command : './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache',
125-
filesToCheck : [ 'psalm.xml.dist', 'psalm.xml' ],
126-
toolType : ToolType.CODE_CHECK,
127-
lintConfigCommand : 'xmllint --schema vendor/vimeo/psalm/config.xsd',
128-
},
129-
{
130-
executionType : ToolExecutionType.STATIC,
131-
name : 'Composer Require Checker',
132-
command : './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json',
133-
filesToCheck : [ 'composer-require-checker.json' ],
134-
toolType : ToolType.CODE_CHECK,
135-
},
136-
{
137-
executionType : ToolExecutionType.STATIC,
138-
name : 'PHPBench',
139-
command : './vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate',
140-
filesToCheck : [ 'phpbench.json' ],
141-
toolType : ToolType.CODE_CHECK,
142-
},
143-
{
144-
executionType : ToolExecutionType.STATIC,
145-
name : 'Codeception',
146-
command : './vendor/bin/codecept run',
147-
filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ],
148-
toolType : ToolType.CODE_CHECK,
149-
},
150-
{
151-
executionType : ToolExecutionType.STATIC,
152-
name : 'PHP CS Fixer',
153-
command : './vendor/bin/php-cs-fixer fix -v --diff --dry-run',
154-
filesToCheck : [ '.php-cs-fixer.php', '.php-cs-fixer.dist.php' ],
155-
toolType : ToolType.CODE_CHECK,
156-
},
78+
PHPUnitTool,
79+
InfectionTool,
80+
PhpCodeSnifferTool,
81+
PsalmTool,
82+
ComposerRequireCheckerTool,
83+
PhpBenchTool,
84+
CodeceptionTool,
85+
PhpCsFixerTool,
86+
PHPStanTool,
15787
backwardCompatibilityCheckTool(config),
15888
].filter((tool) => tool !== null) as Tool[];
15989

src/tools/codeception.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ToolExecutionType} from '../enum/toolExecutionType';
2+
import {ToolType} from '../enum/toolType';
3+
4+
export const CodeceptionTool = {
5+
executionType : ToolExecutionType.STATIC,
6+
name : 'Codeception',
7+
command : './vendor/bin/codecept run',
8+
filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ],
9+
toolType : ToolType.CODE_CHECK,
10+
};

src/tools/codesniffer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {ToolType} from '../enum/toolType';
2+
import {ToolExecutionType} from '../enum/toolExecutionType';
3+
4+
export const PhpCodeSnifferTool = {
5+
executionType : ToolExecutionType.STATIC,
6+
name : 'PHPCodeSniffer',
7+
command : './vendor/bin/phpcs -q --report=checkstyle | cs2pr',
8+
filesToCheck : [ 'phpcs.xml', 'phpcs.xml.dist' ],
9+
toolType : ToolType.CODE_CHECK,
10+
lintConfigCommand : 'xmllint --schema vendor/squizlabs/php_codesniffer/phpcs.xsd',
11+
};

src/tools/composerRequireChecker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ToolType} from '../enum/toolType';
2+
import {ToolExecutionType} from '../enum/toolExecutionType';
3+
4+
export const ComposerRequireCheckerTool = {
5+
executionType : ToolExecutionType.STATIC,
6+
name : 'Composer Require Checker',
7+
command : './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json',
8+
filesToCheck : [ 'composer-require-checker.json' ],
9+
toolType : ToolType.CODE_CHECK,
10+
};

src/tools/infection.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {ToolType} from '../enum/toolType';
2+
import {ComposerJson} from '../config/composer';
3+
import parseJsonFile from '../json';
4+
import {ToolExecutionType} from '../enum/toolExecutionType';
5+
6+
export const InfectionTool = {
7+
executionType : ToolExecutionType.STATIC,
8+
name : 'Infection',
9+
command : detectInfectionCommand(),
10+
filesToCheck : [ 'infection.json', 'infection.json.dist' ],
11+
toolType : ToolType.CODE_CHECK,
12+
};
13+
14+
function detectInfectionCommand(): string {
15+
const composerJson: ComposerJson = parseJsonFile('composer.json', true) as ComposerJson;
16+
17+
if (composerJson['require-dev']?.['roave/infection-static-analysis-plugin'] !== undefined) {
18+
return 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin';
19+
}
20+
21+
return 'phpdbg -qrr ./vendor/bin/infection';
22+
}

src/tools/phpCsFixer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ToolType} from '../enum/toolType';
2+
import {ToolExecutionType} from '../enum/toolExecutionType';
3+
4+
export const PhpCsFixerTool = {
5+
executionType : ToolExecutionType.STATIC,
6+
name : 'PHP CS Fixer',
7+
command : './vendor/bin/php-cs-fixer fix -v --diff --dry-run',
8+
filesToCheck : [ '.php-cs-fixer.php', '.php-cs-fixer.dist.php' ],
9+
toolType : ToolType.CODE_CHECK,
10+
};

0 commit comments

Comments
 (0)