createSkipped() public static method

public static createSkipped ( GrumPHP\Task\TaskInterface $task, GrumPHP\Task\Context\ContextInterface $context ) : TaskResult
$task GrumPHP\Task\TaskInterface
$context GrumPHP\Task\Context\ContextInterface
return TaskResult
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->path(pathinfo($config['file'], PATHINFO_DIRNAME))->name(pathinfo($config['file'], PATHINFO_BASENAME));
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('composer');
     $arguments->add('validate');
     $arguments->addOptionalArgument('--no-check-all', $config['no_check_all']);
     $arguments->addOptionalArgument('--no-check-lock', $config['no_check_lock']);
     $arguments->addOptionalArgument('--no-check-publish', $config['no_check_publish']);
     $arguments->addOptionalArgument('--with-dependencies', $config['with_dependencies']);
     $arguments->addOptionalArgument('--strict', $config['strict']);
     $arguments->addOptionalArgument('%s', $config['file']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     if ($config['no_local_repository'] && $this->hasLocalRepository($files->first())) {
         return TaskResult::createFailed($this, $context, 'You have at least one local repository declared.');
     }
     return TaskResult::createPassed($this, $context);
 }
 /**
  * @param ContextInterface $context
  * @return TaskResult
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     if (is_file('./vendor/bin/fixbom')) {
         $fixCommand = './vendor/bin/fixbom';
     } elseif (is_file('./bin/fixbom')) {
         $fixCommand = './bin/fixbom';
     } else {
         $fixCommand = 'fixbom';
     }
     $shouldGetFixedLog = [];
     /** @var \Symfony\Component\Finder\SplFileInfo $file */
     foreach ($files as $file) {
         $execFile = $file->getPathname();
         $debugLog[] = $execFile;
         if ($this->isFileWithBOM($execFile)) {
             $shouldGetFixedLog[] = $execFile . " has BOM and should be fixed";
             $fixCommand .= " '" . $execFile . "'";
         }
     }
     if (count($shouldGetFixedLog) > 0) {
         return TaskResult::createFailed($this, $context, implode(PHP_EOL, $shouldGetFixedLog) . PHP_EOL . "you can use this to fix them:" . PHP_EOL . $fixCommand);
     }
     return TaskResult::createPassed($this, $context);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles(false)->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $this->parser->setParserOptions($config);
     $parseErrors = $this->parse($files);
     if ($parseErrors->count()) {
         return TaskResult::createFailed($this, $context, sprintf("Some errors occured while parsing your PHP files:\n%s", $parseErrors->__toString()));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.php');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $arguments = $this->processBuilder->createArgumentsForCommand('phpunit');
     $arguments->addOptionalArgument('--configuration=%s', $config['config_file']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('npm');
     $arguments->addRequiredArgument('%s', $config['script']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->setWorkingDirectory(realpath($config['working_directory']));
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('grunt');
     $arguments->addOptionalArgument('--gruntfile=%s', $config['grunt_file']);
     $arguments->addOptionalArgument('%s', $config['task']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.json');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $this->linter->setDetectKeyConflicts($config['detect_key_conflicts']);
     try {
         $lintErrors = $this->lint($files);
     } catch (RuntimeException $e) {
         return TaskResult::createFailed($this, $context, $e->getMessage());
     }
     if ($lintErrors->count()) {
         return TaskResult::createFailed($this, $context, (string) $lintErrors);
     }
     return TaskResult::createPassed($this, $context);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('doctrine');
     $arguments->add('orm:validate-schema');
     $arguments->addOptionalArgument('--skip-mapping', $config['skip_mapping']);
     $arguments->addOptionalArgument('--skip-sync', $config['skip_sync']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('php7cc');
     $arguments->addOptionalArgument('--level=%s', $config['level']);
     $arguments->addArgumentArrayWithSeparatedValue('--except', $config['exclude']);
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles();
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('git');
     $arguments->add('diff');
     $arguments->add('--name-only');
     $arguments->add('--diff-filter=U');
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if ($process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, sprintf('You have merge conflicts in the following files, please resolve them before you can continue%s%s', PHP_EOL, $this->formatter->format($process)));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions(array('feature'));
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('kawaii');
     $arguments->add('gherkin:check');
     $arguments->addOptionalArgument('--align=%s', $config['align']);
     $arguments->add($config['directory']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('/\\.(yaml|yml)$/i');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $this->linter->setObjectSupport($config['object_support']);
     $this->linter->setExceptionOnInvalidType($config['exception_on_invalid_type']);
     try {
         $lintErrors = $this->lint($files);
     } catch (RuntimeException $e) {
         return TaskResult::createFailed($this, $context, $e->getMessage());
     }
     if ($lintErrors->count()) {
         return TaskResult::createFailed($this, $context, (string) $lintErrors);
     }
     return TaskResult::createPassed($this, $context);
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $exceptions = array();
     foreach ($config['scripts'] as $script) {
         try {
             $this->runShell($script);
         } catch (RuntimeException $e) {
             $exceptions[] = $e->getMessage();
         }
     }
     if (count($exceptions)) {
         return TaskResult::createFailed($this, $context, implode(PHP_EOL, $exceptions));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files) || empty($config['keywords'])) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('git');
     $arguments->add('grep');
     $arguments->add('--cached');
     $arguments->add('-n');
     $arguments->addArgumentArrayWithSeparatedValue('-e', $config['keywords']);
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if ($process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, sprintf('You have blacklisted keywords in your commit:%s%s', PHP_EOL, $this->formatter->format($process)));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->path(pathinfo($config['lockfile'], PATHINFO_DIRNAME))->name(pathinfo($config['lockfile'], PATHINFO_BASENAME));
     if (0 === count($files) && !$config['run_always']) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('security-checker');
     $arguments->add('security:check');
     $arguments->addOptionalArgument('%s', $config['lockfile']);
     $arguments->addOptionalArgument('--format=%s', $config['format']);
     $arguments->addOptionalArgument('--end-point=%s', $config['end_point']);
     $arguments->addOptionalArgument('--timeout=%s', $config['timeout']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $arguments = $this->processBuilder->createArgumentsForCommand('phpmd');
     $arguments->addCommaSeparatedFiles($files);
     $arguments->add('text');
     $arguments->addOptionalCommaSeparatedArgument('%s', $config['ruleset']);
     $arguments->addOptionalArgument('--exclude', !empty($config['exclude']));
     $arguments->addOptionalCommaSeparatedArgument('%s', $config['exclude']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $this->linter->setLoadFromNet($config['load_from_net']);
     $this->linter->setXInclude($config['x_include']);
     $this->linter->setDtdValidation($config['dtd_validation']);
     $this->linter->setSchemeValidation($config['scheme_validation']);
     try {
         $lintErrors = $this->lint($files);
     } catch (RuntimeException $e) {
         return TaskResult::createFailed($this, $context, $e->getMessage());
     }
     if ($lintErrors->count()) {
         return TaskResult::createFailed($this, $context, (string) $lintErrors);
     }
     return TaskResult::createPassed($this, $context);
 }
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.php');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $this->formatter->resetCounter();
     $arguments = $this->processBuilder->createArgumentsForCommand('php-cs-fixer');
     $arguments->add('--format=json');
     $arguments->addOptionalArgument('--level=%s', $config['level']);
     $arguments->addOptionalArgument('--config=%s', $config['config']);
     $arguments->addOptionalArgument('--config-file=%s', $config['config_file']);
     $arguments->addOptionalArgument('--verbose', $config['verbose']);
     $arguments->addOptionalCommaSeparatedArgument('--fixers=%s', $config['fixers']);
     $arguments->add('fix');
     if ($context instanceof RunContext && $config['config_file'] !== null) {
         return $this->runOnAllFiles($context, $arguments);
     }
     return $this->runOnChangedFiles($context, $arguments, $files);
 }
Example #19
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.php');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $arguments = $this->processBuilder->createArgumentsForCommand('atoum');
     $arguments->addOptionalArgumentWithSeparatedValue('-c', $config['config_file']);
     $arguments->addOptionalArgumentWithSeparatedValue('--bootstrap-file', $config['bootstrap_file']);
     $arguments->addSeparatedArgumentArray('--directories', $config['directories']);
     $arguments->addSeparatedArgumentArray('--files', $config['files']);
     $arguments->addSeparatedArgumentArray('--namespaces', $config['namespaces']);
     $arguments->addSeparatedArgumentArray('--methods', $config['methods']);
     $arguments->addSeparatedArgumentArray('--tags', $config['tags']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     /** @var array $config */
     $config = $this->getConfiguration();
     /** @var array $whitelistPatterns */
     $whitelistPatterns = $config['whitelist_patterns'];
     /** @var array $extensions */
     $extensions = $config['triggered_by'];
     /** @var \GrumPHP\Collection\FilesCollection $files */
     $files = $context->getFiles();
     if (0 !== count($whitelistPatterns)) {
         $files = $files->paths($whitelistPatterns);
     }
     $files = $files->extensions($extensions);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('phpcs');
     $arguments = $this->addArgumentsFromConfig($arguments, $config);
     $arguments->add('--report-full');
     $arguments->add('--report-json');
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         $output = $this->formatter->format($process);
         try {
             $arguments = $this->processBuilder->createArgumentsForCommand('phpcbf');
             $arguments = $this->addArgumentsFromConfig($arguments, $config);
             $output .= $this->formatter->formatErrorMessage($arguments, $this->processBuilder);
         } catch (RuntimeException $exception) {
             // phpcbf could not get found.
             $output .= PHP_EOL . 'Info: phpcbf could not get found. Please consider to install it for suggestions.';
         }
         return TaskResult::createFailed($this, $context, $output);
     }
     return TaskResult::createPassed($this, $context);
 }
Example #21
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $arguments = $this->processBuilder->createArgumentsForCommand('phpcs');
     $arguments->addOptionalArgument('--standard=%s', $config['standard']);
     $arguments->addOptionalArgument('--warning-severity=0', !$config['show_warnings']);
     $arguments->addOptionalArgument('--tab-width=%s', $config['tab_width']);
     $arguments->addOptionalArgument('--encoding=%s', $config['encoding']);
     $arguments->addOptionalCommaSeparatedArgument('--sniffs=%s', $config['sniffs']);
     $arguments->addOptionalCommaSeparatedArgument('--ignore=%s', $config['ignore_patterns']);
     $arguments->addFiles($files);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $files = $context->getFiles()->name('*.php');
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $config = $this->getConfiguration();
     $this->formatter->resetCounter();
     $arguments = $this->processBuilder->createArgumentsForCommand('php-cs-fixer');
     $arguments->add('--format=json');
     $arguments->add('--dry-run');
     $arguments->addOptionalArgument('--allow-risky=%s', $config['allow_risky']);
     $arguments->addOptionalArgument('--cache-file=%s', $config['cache_file']);
     $arguments->addOptionalArgument('--config=%s', $config['config']);
     $arguments->addOptionalArgument('--rules=%s', $config['rules']);
     $arguments->addOptionalArgument('--using-cache=%s', $config['using_cache']);
     $arguments->addOptionalArgument('--path-mode=%s', $config['path_mode']);
     $arguments->addOptionalArgument('--verbose', $config['verbose']);
     $arguments->add('fix');
     if ($context instanceof RunContext && $config['config'] !== null) {
         return $this->runOnAllFiles($context, $arguments);
     }
     return $this->runOnChangedFiles($context, $arguments, $files);
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $config = $this->getConfiguration();
     $files = $context->getFiles()->extensions($config['triggered_by']);
     if (0 === count($files)) {
         return TaskResult::createSkipped($this, $context);
     }
     $arguments = $this->processBuilder->createArgumentsForCommand('phpcpd');
     $extensions = array_map(function ($extension) {
         return sprintf('*.%s', $extension);
     }, $config['triggered_by']);
     $arguments->addArgumentArray('--exclude=%s', $config['exclude']);
     $arguments->addRequiredArgument('--min-lines=%u', $config['min_lines']);
     $arguments->addRequiredArgument('--min-tokens=%u', $config['min_tokens']);
     $arguments->addOptionalCommaSeparatedArgument('--names=%s', $extensions);
     $arguments->addOptionalArgument('--fuzzy', $config['fuzzy']);
     $arguments->add($config['directory']);
     $process = $this->processBuilder->buildProcess($arguments);
     $process->run();
     if (!$process->isSuccessful()) {
         return TaskResult::createFailed($this, $context, $this->formatter->format($process));
     }
     return TaskResult::createPassed($this, $context);
 }