Skip to content

Commit 488072b

Browse files
committed
refactor: move some tools to dedicated files
Due to the new PHPStan tool, we exceeded the line-length limit of 100 lines per file. Signed-off-by: Maximilian Bösing <[email protected]>
1 parent 32b63c2 commit 488072b

File tree

10 files changed

+115
-79
lines changed

10 files changed

+115
-79
lines changed

src/tools.ts

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
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';
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';
613

714
export enum ToolExecutionType {
815
/**
@@ -18,7 +25,7 @@ export enum ToolExecutionType {
1825
STATIC = 'static',
1926
}
2027

21-
enum ToolType {
28+
export enum ToolType {
2229
LINTER = 'linter',
2330
CODE_CHECK = 'code_check',
2431
}
@@ -36,16 +43,6 @@ export type ToolRunningContainerDefaultPhpVersion = Tool & {
3643
php: typeof CONTAINER_DEFAULT_PHP_VERSION,
3744
}
3845

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-
4946
function backwardCompatibilityCheckTool(config: Config): ToolRunningContainerDefaultPhpVersion | null {
5047
if (!config.backwardCompatibilityCheck) {
5148
return null;
@@ -95,72 +92,15 @@ export default function createTools(config: Config): Array<Tool> {
9592
filesToCheck : [ 'README.md' ],
9693
toolType : ToolType.LINTER,
9794
},
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-
},
157-
{
158-
executionType : ToolExecutionType.STATIC,
159-
name : 'PHPStan',
160-
command : './vendor/bin/phpstan analyse --error-format=github --ansi --no-progress',
161-
filesToCheck : [ 'phpstan.neon', 'phpstan.neon.dist', 'phpstan.dist.neon' ],
162-
toolType : ToolType.CODE_CHECK,
163-
},
95+
PHPUnitTool,
96+
InfectionTool,
97+
PhpCodeSnifferTool,
98+
PsalmTool,
99+
ComposerRequireCheckerTool,
100+
PhpBenchTool,
101+
CodeceptionTool,
102+
PhpCsFixerTool,
103+
PHPStanTool,
164104
backwardCompatibilityCheckTool(config),
165105
].filter((tool) => tool !== null) as Tool[];
166106

src/tools/codeception.ts

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

src/tools/codesniffer.ts

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

src/tools/composerRequireChecker.ts

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

src/tools/infection.ts

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

src/tools/phpCsFixer.ts

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

src/tools/phpbench.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {ToolExecutionType, ToolType} from '../tools';
2+
3+
export const PhpBenchTool = {
4+
executionType : ToolExecutionType.STATIC,
5+
name : 'PHPBench',
6+
command : './vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate',
7+
filesToCheck : [ 'phpbench.json' ],
8+
toolType : ToolType.CODE_CHECK,
9+
};

src/tools/phpstan.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {ToolExecutionType, ToolType} from '../tools';
2+
3+
export const PHPStanTool = {
4+
executionType : ToolExecutionType.STATIC,
5+
name : 'PHPStan',
6+
command : './vendor/bin/phpstan analyse --error-format=github --ansi --no-progress',
7+
filesToCheck : [ 'phpstan.neon', 'phpstan.neon.dist', 'phpstan.dist.neon' ],
8+
toolType : ToolType.CODE_CHECK,
9+
};

src/tools/phpunit.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ToolExecutionType, ToolType} from '../tools';
2+
3+
export const PHPUnitTool = {
4+
executionType : ToolExecutionType.MATRIX,
5+
name : 'PHPUnit',
6+
command : './vendor/bin/phpunit',
7+
filesToCheck : [ 'phpunit.xml.dist', 'phpunit.xml' ],
8+
toolType : ToolType.CODE_CHECK,
9+
lintConfigCommand : 'xmllint --schema vendor/phpunit/phpunit/phpunit.xsd',
10+
};

src/tools/psalm.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ToolExecutionType, ToolType} from '../tools';
2+
3+
export const PsalmTool = {
4+
executionType : ToolExecutionType.STATIC,
5+
name : 'Psalm',
6+
command : './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache',
7+
filesToCheck : [ 'psalm.xml.dist', 'psalm.xml' ],
8+
toolType : ToolType.CODE_CHECK,
9+
lintConfigCommand : 'xmllint --schema vendor/vimeo/psalm/config.xsd',
10+
};

0 commit comments

Comments
 (0)