Skip to content

Commit

Permalink
refactor: move some tools to dedicated files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
boesing committed Sep 26, 2024
1 parent 32b63c2 commit 488072b
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 79 deletions.
98 changes: 19 additions & 79 deletions src/tools.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
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';
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';

export enum ToolExecutionType {
/**
Expand All @@ -18,7 +25,7 @@ export enum ToolExecutionType {
STATIC = 'static',
}

enum ToolType {
export enum ToolType {
LINTER = 'linter',
CODE_CHECK = 'code_check',
}
Expand All @@ -36,16 +43,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;
Expand Down Expand Up @@ -95,72 +92,15 @@ export default function createTools(config: Config): Array<Tool> {
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[];

Expand Down
9 changes: 9 additions & 0 deletions src/tools/codeception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ToolExecutionType, ToolType} from '../tools';

export const CodeceptionTool = {
executionType : ToolExecutionType.STATIC,
name : 'Codeception',
command : './vendor/bin/codecept run',
filesToCheck : [ 'codeception.yml.dist', 'codeception.yml' ],
toolType : ToolType.CODE_CHECK,
};
10 changes: 10 additions & 0 deletions src/tools/codesniffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ToolExecutionType, ToolType} from '../tools';

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',
};
9 changes: 9 additions & 0 deletions src/tools/composerRequireChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ToolExecutionType, ToolType} from '../tools';

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,
};
21 changes: 21 additions & 0 deletions src/tools/infection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {ToolExecutionType, ToolType} from '../tools';
import {ComposerJson} from '../config/composer';
import parseJsonFile from '../json';

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';
}
9 changes: 9 additions & 0 deletions src/tools/phpCsFixer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ToolExecutionType, ToolType} from '../tools';

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,
};
9 changes: 9 additions & 0 deletions src/tools/phpbench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ToolExecutionType, ToolType} from '../tools';

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,
};
9 changes: 9 additions & 0 deletions src/tools/phpstan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ToolExecutionType, ToolType} from '../tools';

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,
};
10 changes: 10 additions & 0 deletions src/tools/phpunit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ToolExecutionType, ToolType} from '../tools';

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',
};
10 changes: 10 additions & 0 deletions src/tools/psalm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ToolExecutionType, ToolType} from '../tools';

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',
};

0 comments on commit 488072b

Please sign in to comment.