readFromFileInfo() public method

public readFromFileInfo ( SplFileInfo $file ) : string
$file SplFileInfo
return string
Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #3
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);
 }
Beispiel #4
0
 /**
  * @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;
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
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);
 }
Beispiel #7
0
 /**
  * Load an ascii image
  *
  * @param $resource
  *
  * @return string
  */
 public function getAsciiContent($resource)
 {
     $file = $this->config->getAsciiContentPath($resource);
     // Disabled:
     if (is_null($file)) {
         return '';
     }
     // Specified by user:
     if ($this->fileSystem->exists($file)) {
         return $this->fileSystem->readFromFileInfo($file);
     }
     // Embedded ASCII art:
     $embeddedFile = $this->getAsciiPath() . $file;
     if ($this->fileSystem->exists($embeddedFile)) {
         return $this->fileSystem->readFromFileInfo(new SplFileInfo($embeddedFile));
     }
     // Error:
     return sprintf('ASCII file %s could not be found.', $file);
 }
Beispiel #8
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);
 }
Beispiel #9
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);
 }