diff --git a/README.md b/README.md index 73ec6b7..d5dbc8a 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,10 @@ Example: Alias: `import-db|db-import|importdb|dbimport|import_db|db_import` + - `local:lint:php`: Runs and configure Phpcs for you local env. + + Alias: `phpcs` + - `local:setup`: Setups your project from scratch (lando, ddev), all your data will be destroy and rebuild. Alias: `setup` diff --git a/assets/templates/phpcs.xml b/assets/templates/phpcs.xml new file mode 100644 index 0000000..74d608e --- /dev/null +++ b/assets/templates/phpcs.xml @@ -0,0 +1,33 @@ + + + PHP CodeSniffer configuration for myproject development. + web/modules/custom + web/themes/custom + vendor + contrib + tests + pattern-lab + patternlab + node_modules + *components/_twig-components* + */themes/custom/**/dist/* + + + + + + + + + + + + diff --git a/src/Robo/Plugin/Commands/LintPhpCommand.php b/src/Robo/Plugin/Commands/LintPhpCommand.php new file mode 100644 index 0000000..ce8d915 --- /dev/null +++ b/src/Robo/Plugin/Commands/LintPhpCommand.php @@ -0,0 +1,49 @@ +getLocalEnvRoot() . '/composer.json'); + $composerJson = json_decode($composerJson, TRUE); + $installComposerPackages = FALSE; + $createPhpCsFile = FALSE; + if (!isset($composerJson['require-dev']['drupal/coder'])) { + $installComposerPackages = $io->confirm("You don't have the Coder composer package installed, Do you want us to install it for you (Required for linting)?", TRUE); + } + if (!file_exists($this->getLocalEnvRoot() . '/phpcs.xml')) { + $createPhpCsFile = $io->confirm("You don't have a Base PHPCS configuration file (phpcs.xml), Do you want us to create one for your Project?", TRUE); + } + $tasks = $this->collectionBuilder($io); + if ($installComposerPackages) { + $tasks->addTask($this->taskComposerRequire() + ->dependency('drupal/coder') + ->dir($this->getLocalEnvRoot()) + ->dev() + ->ignorePlatformRequirements() + ); + } + if ($createPhpCsFile) { + $assets = dirname(__DIR__, 4) . '/assets/templates/'; + $tasks->addTask($this->taskFilesystemStack()->copy($assets . 'phpcs.xml', $this->getLocalEnvRoot() . '/phpcs.xml')); + } + $tasks->addTask($this->taskExec('./vendor/bin/phpcs -d memory_limit=-1')); + return $tasks; + } +}