Example #1
0
File: Hooks.php Project: lin3s/cs
 /**
  * Static method that allows to create a .editorconfig symlink,
  * .scss_lint.yml and .eslint.yml files when Composer throws the
  * install or update commands.
  */
 public static function addFiles()
 {
     $app = new Application();
     ScssLint::scssLintFile($app->parameters());
     EsLint::esLintFile($app->parameters());
     $editorConfig = __DIR__ . '/../../../../../.editorconfig';
     $fileSystem = new Filesystem();
     try {
         $fileSystem->remove($editorConfig);
         $fileSystem->symlink(__DIR__ . '/../../.editorconfig', $editorConfig, true);
     } catch (\Exception $exception) {
         echo sprintf("Something wrong happens during the symlink process: \n%s\n", $exception->getMessage());
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $output->writeln(sprintf('<fg=white;options=bold;bg=red>%s</fg=white;options=bold;bg=red>', $this->name));
     $output->writeln('<info>Fetching files...</info>');
     $files = Git::committedFiles();
     $output->writeln('<info>Check composer</info>');
     Composer::check($files);
     if (in_array('phpformatter', $this->parameters['enabled'])) {
         $output->writeln('<info>Checking uses and license headers with PHP-formatter</info>');
         PHPFormatter::check($files, $this->parameters);
     }
     if (in_array('phpcsfixer', $this->parameters['enabled'])) {
         $output->writeln('<info>Fixing PHP code style with PHP-CS-Fixer</info>');
         PhpCsFixer::check($files, $this->parameters);
     }
     if (in_array('phpmd', $this->parameters['enabled'])) {
         $output->writeln('<info>Checking code mess with PHPMD</info>');
         $phpmdResult = Phpmd::check($files, $this->parameters);
         if (count($phpmdResult) > 0) {
             foreach ($phpmdResult as $error) {
                 $output->writeln($error->output());
             }
             throw new CheckFailException('PHPMD');
         }
     }
     if (in_array('scsslint', $this->parameters['enabled'])) {
         $output->writeln('<info>Checking scss files with Scss-lint</info>');
         $scssLintResult = ScssLint::check($files, $this->parameters);
         if (count($scssLintResult) > 0) {
             foreach ($scssLintResult as $error) {
                 $output->writeln($error->output());
             }
             throw new CheckFailException('Scss-lint');
         }
     }
     if (in_array('eslint', $this->parameters['enabled'])) {
         $output->writeln('<info>Checking js files with ESLint</info>');
         $esLintResult = EsLint::check($files, $this->parameters);
         if (count($esLintResult) > 0) {
             foreach ($esLintResult as $error) {
                 $output->writeln($error->output());
             }
             throw new CheckFailException('ESLint');
         }
     }
     Git::addFiles($files, $this->parameters['root_directory']);
     $output->writeln('<info>Nice commit man!</info>');
 }