diff --git a/src/config/app.ts b/src/config/app.ts index 12005b8..9bd24e1 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -1,8 +1,9 @@ import fs, {PathLike} from 'fs'; import semver from 'semver'; import parseJsonFile from '../json'; -import {isToolRunningContainerDefaultPhpVersion, Tool, ToolExecutionType} from '../tools'; +import {isToolRunningContainerDefaultPhpVersion, Tool} from '../tools'; import {Logger} from '../logging'; +import {ToolExecutionType} from '../enum/toolExecutionType'; import { CONTAINER_DEFAULT_PHP_VERSION, CURRENT_STABLE, diff --git a/src/enum/toolExecutionType.ts b/src/enum/toolExecutionType.ts new file mode 100644 index 0000000..2ccd418 --- /dev/null +++ b/src/enum/toolExecutionType.ts @@ -0,0 +1,13 @@ +export enum ToolExecutionType { + /** + * @description Executed on every supported PHP version with lowest & latest dependencies. + * In case, a lock-file is present, the minimum supported PHP version will also run with LOCKED + * dependencies. + */ + MATRIX = 'matrix', + + /** + * @description Executed on the minimum PHP version with either LOCKED or LATEST dependencies. + */ + STATIC = 'static', +} diff --git a/src/enum/toolType.ts b/src/enum/toolType.ts new file mode 100644 index 0000000..6696a4b --- /dev/null +++ b/src/enum/toolType.ts @@ -0,0 +1,4 @@ +export enum ToolType { + LINTER = 'linter', + CODE_CHECK = 'code_check', +} diff --git a/src/tools.ts b/src/tools.ts index b2f8d69..8fb5daf 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -1,27 +1,17 @@ import fs, {PathLike} from 'fs'; import {Config} from './config/app'; -import {ComposerJson} from './config/composer'; -import parseJsonFile from './json'; import {CONTAINER_DEFAULT_PHP_VERSION} from './config/php'; - -export enum ToolExecutionType { - /** - * @description Executed on every supported PHP version with lowest & latest dependencies. - * In case, a lock-file is present, the minimum supported PHP version will also run with LOCKED - * dependencies. - */ - MATRIX = 'matrix', - - /** - * @description Executed on the minimum PHP version with either LOCKED or LATEST dependencies. - */ - STATIC = 'static', -} - -enum ToolType { - LINTER = 'linter', - CODE_CHECK = 'code_check', -} +import {PHPUnitTool} from './tools/phpunit'; +import {InfectionTool} from './tools/infection'; +import {PhpCodeSnifferTool} from './tools/codesniffer'; +import {PsalmTool} from './tools/psalm'; +import {ComposerRequireCheckerTool} from './tools/composerRequireChecker'; +import {PhpBenchTool} from './tools/phpbench'; +import {CodeceptionTool} from './tools/codeception'; +import {PhpCsFixerTool} from './tools/phpCsFixer'; +import {PHPStanTool} from './tools/phpstan'; +import {ToolExecutionType} from './enum/toolExecutionType'; +import {ToolType} from './enum/toolType'; export type Tool = { executionType: ToolExecutionType, @@ -36,16 +26,6 @@ export type ToolRunningContainerDefaultPhpVersion = Tool & { php: typeof CONTAINER_DEFAULT_PHP_VERSION, } -function detectInfectionCommand(): string { - const composerJson: ComposerJson = parseJsonFile('composer.json', true) as ComposerJson; - - if (composerJson['require-dev']?.['roave/infection-static-analysis-plugin'] !== undefined) { - return 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin'; - } - - return 'phpdbg -qrr ./vendor/bin/infection'; -} - function backwardCompatibilityCheckTool(config: Config): ToolRunningContainerDefaultPhpVersion | null { if (!config.backwardCompatibilityCheck) { return null; @@ -95,72 +75,15 @@ export default function createTools(config: Config): Array { filesToCheck : [ 'README.md' ], toolType : ToolType.LINTER, }, - { - executionType : ToolExecutionType.MATRIX, - name : 'PHPUnit', - command : './vendor/bin/phpunit', - filesToCheck : [ 'phpunit.xml.dist', 'phpunit.xml' ], - toolType : ToolType.CODE_CHECK, - lintConfigCommand : 'xmllint --schema vendor/phpunit/phpunit/phpunit.xsd', - }, - { - executionType : ToolExecutionType.STATIC, - name : 'Infection', - command : detectInfectionCommand(), - filesToCheck : [ 'infection.json', 'infection.json.dist' ], - toolType : ToolType.CODE_CHECK, - }, - { - executionType : ToolExecutionType.STATIC, - name : 'PHPCodeSniffer', - command : './vendor/bin/phpcs -q --report=checkstyle | cs2pr', - filesToCheck : [ 'phpcs.xml', 'phpcs.xml.dist' ], - toolType : ToolType.CODE_CHECK, - lintConfigCommand : 'xmllint --schema vendor/squizlabs/php_codesniffer/phpcs.xsd', - }, - { - executionType : ToolExecutionType.STATIC, - name : 'Psalm', - command : './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache', - filesToCheck : [ 'psalm.xml.dist', 'psalm.xml' ], - toolType : ToolType.CODE_CHECK, - lintConfigCommand : 'xmllint --schema vendor/vimeo/psalm/config.xsd', - }, - { - executionType : ToolExecutionType.STATIC, - name : 'Composer Require Checker', - command : './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json', - filesToCheck : [ 'composer-require-checker.json' ], - toolType : ToolType.CODE_CHECK, - }, - { - executionType : ToolExecutionType.STATIC, - name : 'PHPBench', - command : './vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate', - filesToCheck : [ 'phpbench.json' ], - toolType : ToolType.CODE_CHECK, - }, - { - executionType : ToolExecutionType.STATIC, - name : 'Codeception', - command : './vendor/bin/codecept run', - filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ], - toolType : ToolType.CODE_CHECK, - }, - { - executionType : ToolExecutionType.STATIC, - name : 'PHP CS Fixer', - command : './vendor/bin/php-cs-fixer fix -v --diff --dry-run', - filesToCheck : [ '.php-cs-fixer.php', '.php-cs-fixer.dist.php' ], - toolType : ToolType.CODE_CHECK, - }, - { - executionType : ToolExecutionType.STATIC, - name : 'PHPStan', - command : './vendor/bin/phpstan analyse --error-format=github --ansi --no-progress', - filesToCheck : [ 'phpstan.neon', 'phpstan.neon.dist', 'phpstan.dist.neon' ], - toolType : ToolType.CODE_CHECK, - }, + PHPUnitTool, + InfectionTool, + PhpCodeSnifferTool, + PsalmTool, + ComposerRequireCheckerTool, + PhpBenchTool, + CodeceptionTool, + PhpCsFixerTool, + PHPStanTool, backwardCompatibilityCheckTool(config), ].filter((tool) => tool !== null) as Tool[]; diff --git a/src/tools/codeception.ts b/src/tools/codeception.ts new file mode 100644 index 0000000..006d674 --- /dev/null +++ b/src/tools/codeception.ts @@ -0,0 +1,10 @@ +import {ToolExecutionType} from '../enum/toolExecutionType'; +import {ToolType} from '../enum/toolType'; + +export const CodeceptionTool = { + executionType : ToolExecutionType.STATIC, + name : 'Codeception', + command : './vendor/bin/codecept run', + filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ], + toolType : ToolType.CODE_CHECK, +}; diff --git a/src/tools/codesniffer.ts b/src/tools/codesniffer.ts new file mode 100644 index 0000000..4b902b1 --- /dev/null +++ b/src/tools/codesniffer.ts @@ -0,0 +1,11 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PhpCodeSnifferTool = { + executionType : ToolExecutionType.STATIC, + name : 'PHPCodeSniffer', + command : './vendor/bin/phpcs -q --report=checkstyle | cs2pr', + filesToCheck : [ 'phpcs.xml', 'phpcs.xml.dist' ], + toolType : ToolType.CODE_CHECK, + lintConfigCommand : 'xmllint --schema vendor/squizlabs/php_codesniffer/phpcs.xsd', +}; diff --git a/src/tools/composerRequireChecker.ts b/src/tools/composerRequireChecker.ts new file mode 100644 index 0000000..1ad7776 --- /dev/null +++ b/src/tools/composerRequireChecker.ts @@ -0,0 +1,10 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const ComposerRequireCheckerTool = { + executionType : ToolExecutionType.STATIC, + name : 'Composer Require Checker', + command : './vendor/bin/composer-require-checker check --config-file=composer-require-checker.json -n -v composer.json', + filesToCheck : [ 'composer-require-checker.json' ], + toolType : ToolType.CODE_CHECK, +}; diff --git a/src/tools/infection.ts b/src/tools/infection.ts new file mode 100644 index 0000000..3f1c247 --- /dev/null +++ b/src/tools/infection.ts @@ -0,0 +1,22 @@ +import {ToolType} from '../enum/toolType'; +import {ComposerJson} from '../config/composer'; +import parseJsonFile from '../json'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const InfectionTool = { + executionType : ToolExecutionType.STATIC, + name : 'Infection', + command : detectInfectionCommand(), + filesToCheck : [ 'infection.json', 'infection.json.dist' ], + toolType : ToolType.CODE_CHECK, +}; + +function detectInfectionCommand(): string { + const composerJson: ComposerJson = parseJsonFile('composer.json', true) as ComposerJson; + + if (composerJson['require-dev']?.['roave/infection-static-analysis-plugin'] !== undefined) { + return 'phpdbg -qrr ./vendor/bin/roave-infection-static-analysis-plugin'; + } + + return 'phpdbg -qrr ./vendor/bin/infection'; +} diff --git a/src/tools/phpCsFixer.ts b/src/tools/phpCsFixer.ts new file mode 100644 index 0000000..c67e854 --- /dev/null +++ b/src/tools/phpCsFixer.ts @@ -0,0 +1,10 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PhpCsFixerTool = { + executionType : ToolExecutionType.STATIC, + name : 'PHP CS Fixer', + command : './vendor/bin/php-cs-fixer fix -v --diff --dry-run', + filesToCheck : [ '.php-cs-fixer.php', '.php-cs-fixer.dist.php' ], + toolType : ToolType.CODE_CHECK, +}; diff --git a/src/tools/phpbench.ts b/src/tools/phpbench.ts new file mode 100644 index 0000000..d3a0199 --- /dev/null +++ b/src/tools/phpbench.ts @@ -0,0 +1,10 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PhpBenchTool = { + executionType : ToolExecutionType.STATIC, + name : 'PHPBench', + command : './vendor/bin/phpbench run --revs=2 --iterations=2 --report=aggregate', + filesToCheck : [ 'phpbench.json' ], + toolType : ToolType.CODE_CHECK, +}; diff --git a/src/tools/phpstan.ts b/src/tools/phpstan.ts new file mode 100644 index 0000000..85e0cee --- /dev/null +++ b/src/tools/phpstan.ts @@ -0,0 +1,10 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PHPStanTool = { + executionType : ToolExecutionType.STATIC, + name : 'PHPStan', + command : './vendor/bin/phpstan analyse --error-format=github --ansi --no-progress', + filesToCheck : [ 'phpstan.neon', 'phpstan.neon.dist', 'phpstan.dist.neon' ], + toolType : ToolType.CODE_CHECK, +}; diff --git a/src/tools/phpunit.ts b/src/tools/phpunit.ts new file mode 100644 index 0000000..049b534 --- /dev/null +++ b/src/tools/phpunit.ts @@ -0,0 +1,11 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PHPUnitTool = { + executionType : ToolExecutionType.MATRIX, + name : 'PHPUnit', + command : './vendor/bin/phpunit', + filesToCheck : [ 'phpunit.xml.dist', 'phpunit.xml' ], + toolType : ToolType.CODE_CHECK, + lintConfigCommand : 'xmllint --schema vendor/phpunit/phpunit/phpunit.xsd', +}; diff --git a/src/tools/psalm.ts b/src/tools/psalm.ts new file mode 100644 index 0000000..6f9c682 --- /dev/null +++ b/src/tools/psalm.ts @@ -0,0 +1,11 @@ +import {ToolType} from '../enum/toolType'; +import {ToolExecutionType} from '../enum/toolExecutionType'; + +export const PsalmTool = { + executionType : ToolExecutionType.STATIC, + name : 'Psalm', + command : './vendor/bin/psalm --shepherd --stats --output-format=github --no-cache', + filesToCheck : [ 'psalm.xml.dist', 'psalm.xml' ], + toolType : ToolType.CODE_CHECK, + lintConfigCommand : 'xmllint --schema vendor/vimeo/psalm/config.xsd', +};