상속: extends Symfony\Component\Filesystem\Filesystem
예제 #1
0
 /**
  * @param string $path path to grumphp.yml
  *
  * @return ContainerBuilder
  */
 public static function buildFromConfiguration($path)
 {
     $container = new ContainerBuilder();
     $container->setProxyInstantiator(new RuntimeInstantiator());
     // Add compiler passes:
     $container->addCompilerPass(new Compiler\ExtensionCompilerPass());
     $container->addCompilerPass(new Compiler\PhpParserCompilerPass());
     $container->addCompilerPass(new Compiler\TaskCompilerPass());
     $container->addCompilerPass(new RegisterListenersPass('event_dispatcher', 'grumphp.event_listener', 'grumphp.event_subscriber'));
     // Load basic service file + custom user configuration
     $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../../resources/config'));
     $loader->load('formatter.yml');
     $loader->load('linters.yml');
     $loader->load('parameters.yml');
     $loader->load('parsers.yml');
     $loader->load('services.yml');
     $loader->load('subscribers.yml');
     $loader->load('tasks.yml');
     $loader->load('util.yml');
     // Load grumphp.yml file:
     $filesystem = new Filesystem();
     if ($filesystem->exists($path)) {
         $loader->load($path);
     }
     // Compile configuration to make sure that tasks are added to the taskrunner
     $container->compile();
     return $container;
 }
예제 #2
0
 function it_should_locate_config_file_on_empty_composer_configuration(Filesystem $filesystem, PackageInterface $package)
 {
     $package->getExtra()->willReturn([]);
     $filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/grumphp.yml'));
 }
예제 #3
0
 /**
  * @param $defaultPath
  *
  * @return string
  */
 private function locateConfigFileWithDistSupport($defaultPath)
 {
     $distPath = strpos($defaultPath, -5) !== '.dist' ? $defaultPath . '.dist' : $defaultPath;
     if ($this->filesystem->exists($defaultPath) || !$this->filesystem->exists($distPath)) {
         return $defaultPath;
     }
     return $distPath;
 }
예제 #4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $gitHooksPath = $this->paths()->getGitHooksDir();
     foreach (InitCommand::$hooks as $hook) {
         $hookPath = $gitHooksPath . $hook;
         if (!$this->filesystem->exists($hookPath)) {
             continue;
         }
         $this->filesystem->remove($hookPath);
     }
     $output->writeln('<fg=yellow>GrumPHP stopped sniffing your commits! Too bad ...<fg=yellow>');
 }
예제 #5
0
 /**
  * @param SplFileInfo $file
  *
  * @return mixed
  * @throws \Seld\JsonLint\ParsingException
  */
 public function lint(SplFileInfo $file)
 {
     $errors = new LintErrorsCollection();
     $flags = $this->calculateFlags();
     try {
         $json = $this->filesystem->readFromFileInfo($file);
         $this->jsonParser->parse($json, $flags);
     } catch (ParsingException $exception) {
         $errors->add(JsonLintError::fromParsingException($file, $exception));
     }
     return $errors;
 }
예제 #6
0
 /**
  * @param SplFileInfo $file
  *
  * @return LintErrorsCollection
  */
 public function lint(SplFileInfo $file)
 {
     $errors = new LintErrorsCollection();
     try {
         $content = $this->filesystem->readFromFileInfo($file);
         $this->parseYaml($content);
     } catch (ParseException $exception) {
         $exception->setParsedFile($file->getPathname());
         $errors[] = YamlLintError::fromParseException($exception);
     }
     return $errors;
 }
예제 #7
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output);
     $files = $this->getCommittedFiles($io);
     $gitUser = $input->getOption('git-user');
     $gitEmail = $input->getOption('git-email');
     $commitMsgPath = $input->getArgument('commit-msg-file');
     $commitMsgFile = new SplFileInfo($commitMsgPath);
     $commitMsg = $this->filesystem->readFromFileInfo($commitMsgFile);
     $output->writeln('<fg=yellow>GrumPHP detected a commit-msg command.</fg=yellow>');
     $context = new GitCommitMsgContext($files, $commitMsg, $gitUser, $gitEmail);
     return $this->taskRunner()->run($output, $context);
 }
예제 #8
0
파일: PhpParser.php 프로젝트: phpro/grumphp
 /**
  * @param SplFileInfo $file
  *
  * @return ParseErrorsCollection
  */
 public function parse(SplFileInfo $file)
 {
     $errors = new ParseErrorsCollection();
     $context = new ParserContext($file, $errors);
     $parser = $this->parserFactory->createFromOptions($this->parserOptions);
     $traverser = $this->traverserFactory->createForTaskContext($this->parserOptions, $context);
     try {
         $code = $this->filesystem->readFromFileInfo($file);
         $stmts = $parser->parse($code);
         $traverser->traverse($stmts);
     } catch (Error $e) {
         $errors->add(PhpParserError::fromParseException($e, $file->getRealPath()));
     }
     return $errors;
 }
예제 #9
0
 /**
  * @param $path
  *
  * @return bool
  */
 public function pathValidator($path)
 {
     if (!$this->filesystem->exists($path)) {
         throw new RuntimeException(sprintf('The path %s could not be found!', $path));
     }
     return $path;
 }
예제 #10
0
파일: Composer.php 프로젝트: phpro/grumphp
 /**
  * Checks if composer.local host one or more local repositories.
  *
  * @param SplFileInfo $composerFile
  *
  * @return bool
  */
 private function hasLocalRepository(SplFileInfo $composerFile)
 {
     $json = $this->filesystem->readFromFileInfo($composerFile);
     $package = json_decode($json, true);
     foreach ($package['repositories'] as $repository) {
         if ($repository['type'] === 'path') {
             return true;
         }
     }
     return false;
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function run(ContextInterface $context)
 {
     $configuration = $this->getConfiguration();
     $percentage = round(min(100, max(0, (double) $configuration['level'])), 2);
     $cloverFile = $configuration['clover_file'];
     if (!$this->filesystem->exists($cloverFile)) {
         return TaskResult::createFailed($this, $context, 'Invalid input file provided');
     }
     if (!$percentage) {
         return TaskResult::createFailed($this, $context, 'An integer checked percentage must be given as second parameter');
     }
     $xml = new SimpleXMLElement($this->filesystem->readFromFileInfo(new SplFileInfo($cloverFile)));
     $totalElements = (string) current($xml->xpath('/coverage/project/metrics/@elements'));
     $checkedElements = (string) current($xml->xpath('/coverage/project/metrics/@coveredelements'));
     $coverage = round($checkedElements / $totalElements * 100, 2);
     if ($coverage < $percentage) {
         $message = sprintf('Code coverage is %1$d%%, which is below the accepted %2$d%%' . PHP_EOL, $coverage, $percentage);
         return TaskResult::createFailed($this, $context, $message);
     }
     return TaskResult::createPassed($this, $context);
 }
예제 #12
0
 /**
  * @param $hook
  * @param $templateFile
  *
  * @return mixed
  */
 protected function parseHookBody($hook, SplFileInfo $templateFile)
 {
     $content = $this->filesystem->readFromFileInfo($templateFile);
     $replacements = ['${HOOK_EXEC_PATH}' => $this->paths()->getGitHookExecutionPath(), '$(HOOK_COMMAND)' => $this->generateHookCommand('git:' . $hook)];
     return str_replace(array_keys($replacements), array_values($replacements), $content);
 }
예제 #13
0
 /**
  * @param $path
  *
  * @return string
  * @throws FileNotFoundException If file doesn't exists
  */
 public function getRelativePath($path)
 {
     $realpath = $this->getAbsolutePath($path);
     return $this->fileSystem->makePathRelative($realpath, $this->getWorkingDir());
 }
예제 #14
0
 function it_succeeds_when_it_has_no_local_repositories(GrumPHP $grumPHP, ProcessBuilder $processBuilder, Filesystem $filesystem, Process $process, ContextInterface $context)
 {
     $composerFile = 'composer.json';
     $grumPHP->getTaskConfiguration('composer')->willReturn(['file' => $composerFile, 'no_local_repository' => true]);
     $arguments = new ProcessArgumentsCollection();
     $processBuilder->createArgumentsForCommand('composer')->willReturn($arguments);
     $processBuilder->buildProcess($arguments)->willReturn($process);
     $process->run()->shouldBeCalled();
     $process->isSuccessful()->willReturn(true);
     $context->getFiles()->willReturn(new FilesCollection([$composerFile = new SplFileInfo($composerFile, '.', $composerFile)]));
     $filesystem->readFromFileInfo($composerFile)->willReturn('{"repositories": [{"type": "vcs", "url": "/"}]}');
     $result = $this->run($context);
     $result->shouldBeAnInstanceOf(TaskResultInterface::class);
     $result->isPassed()->shouldBe(true);
 }