Ejemplo n.º 1
0
 /**
  * @param string $path File or directory to check
  * @param string[] $checkedExtensions Only files having these extensions will be checked
  */
 public function check($path, array $checkedExtensions)
 {
     $isPathDir = is_dir($path);
     $isPathFile = is_file($path);
     if (!$isPathDir && !$isPathFile) {
         throw new \InvalidArgumentException(sprintf('Path %s is not a file or a directory', $path));
     }
     if (!$isPathFile && !$checkedExtensions) {
         throw new \DomainException('At least 1 extension should be specified to check a directory');
     }
     $checkMetadata = new CheckMetadata();
     if (is_file($path)) {
         $context = $this->fileContextFactory->createContext($path);
         $this->contextChecker->checkContext($context);
         $this->resultPrinter->printContext($context);
         $checkMetadata->incrementCheckedFileCount();
     } else {
         $directoryIterator = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::KEY_AS_PATHNAME | \RecursiveDirectoryIterator::CURRENT_AS_FILEINFO | \RecursiveDirectoryIterator::SKIP_DOTS);
         $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::LEAVES_ONLY);
         /** @var \SplFileInfo $fileInfo */
         foreach ($recursiveIterator as $pathName => $fileInfo) {
             if (!in_array($fileInfo->getExtension(), $checkedExtensions)) {
                 continue;
             }
             $context = $this->fileContextFactory->createContext($pathName);
             $this->contextChecker->checkContext($context);
             if (count($context->getMessages())) {
                 $this->resultPrinter->printContext($context);
             }
             $checkMetadata->incrementCheckedFileCount();
         }
     }
     $checkMetadata->endCheck();
     $this->resultPrinter->printMetadata($checkMetadata);
 }
Ejemplo n.º 2
0
 /**
  * @param CheckMetadata $checkMetadata
  * @param SplFileInfo   $fileInfo
  * @param bool          $useRelativePaths
  */
 protected function checkFile(CheckMetadata $checkMetadata, SplFileInfo $fileInfo, $useRelativePaths)
 {
     $context = new FileContext($fileInfo, $useRelativePaths);
     $this->contextChecker->checkContext($context);
     if ($context->hasMessagesOrErrors()) {
         $this->resultPrinter->printContext($context);
     }
     $checkMetadata->incrementCheckedFileCount();
 }
Ejemplo n.º 3
0
 /**
  * @param CheckMetadata $checkMetadata
  * @param string        $pathName
  */
 protected function checkFile(CheckMetadata $checkMetadata, $pathName)
 {
     $context = $this->fileContextFactory->createContext($pathName);
     $this->contextChecker->checkContext($context);
     if ($context->hasMessagesOrErrors()) {
         $this->resultPrinter->printContext($context);
     }
     $checkMetadata->incrementCheckedFileCount();
 }
Ejemplo n.º 4
0
 /**
  * @inheritDoc
  */
 public function printMetadata(CheckMetadata $metadata)
 {
     $this->output->writeln(sprintf('Checked %d file(s) in %f second(s)', $metadata->getCheckedFileCount(), $metadata->getElapsedTime()));
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function printMetadata(CheckMetadata $metadata)
 {
     $checkedFileCount = $metadata->getCheckedFileCount();
     $elapsedTime = $metadata->getElapsedTime();
     $this->output->writeln(sprintf('Checked <fg=green>%d</fg=green> file%s in <fg=green>%.3f</fg=green> second%s', $checkedFileCount, $checkedFileCount > 1 ? 's' : '', $elapsedTime, $elapsedTime > 1 ? 's' : ''));
 }