Skip to content

Commit

Permalink
Merge pull request #32 from fourkitchens/feature/phpcs-command
Browse files Browse the repository at this point in the history
FIre phpCS command
  • Loading branch information
rigoucr authored Jul 8, 2024
2 parents 1baaabf + 98ef36a commit 3c5daaf
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
33 changes: 33 additions & 0 deletions assets/templates/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Standard Drupal Project">
<description>PHP CodeSniffer configuration for myproject development.</description>
<file>web/modules/custom</file>
<file>web/themes/custom</file>
<exclude-pattern>vendor</exclude-pattern>
<exclude-pattern>contrib</exclude-pattern>
<exclude-pattern>tests</exclude-pattern>
<exclude-pattern>pattern-lab</exclude-pattern>
<exclude-pattern>patternlab</exclude-pattern>
<exclude-pattern>node_modules</exclude-pattern>
<exclude-pattern>*components/_twig-components*</exclude-pattern>
<exclude-pattern>*/themes/custom/**/dist/*</exclude-pattern>

<config name="drupal_core_version" value="8"/>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,info"/>

<!-- If you have Coder installed locally then you can reference the Drupal
standards with relative paths. Otherwise simply use "Drupal" and
"DrupalPractice. -->
<rule ref="Drupal">
<!-- Example how you would disable a rule you are not compliant with yet:
<exclude name="Drupal.Commenting.Deprecated"/>
-->
</rule>
<rule ref="DrupalPractice"/>

<!-- Example how you would disable an external rule you do not like:
<rule ref="PEAR.Functions.ValidDefaultValue.NotAtEnd">
<severity>0</severity>
</rule>
-->
</ruleset>
49 changes: 49 additions & 0 deletions src/Robo/Plugin/Commands/LintPhpCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Fire\Robo\Plugin\Commands;

use Robo\Symfony\ConsoleIO;
use Robo\Robo;

/**
* Provides a command To easylly setup and Run phpcs over your local env.
*/
class LintPhpCommand extends FireCommandBase {

/**
* Runs and configure Phpcs for you local env.
*
* Usage Example: fire local:lint:php
*
* @command local:lint:php
* @aliases phpcs
*
*/
public function phpcsRun(ConsoleIO $io) {
$composerJson = file_get_contents($this->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;
}
}

0 comments on commit 3c5daaf

Please sign in to comment.