/** * Build a Symfony2 Finder instance that searches all included paths for files. * * The local config instance will be queried for included and excluded files and the Finder will be populated with * them. * * @return Finder */ protected function buildFinder() { $finder = new Finder(); $finder->in($this->config->getIncludedPaths())->notPath('/vendor/')->files(); foreach ($this->config->getExcludedPaths() as $excluded) { $finder->notPath($excluded); } return $finder; }
/** * Determine the superfluous authors from the passed arrays. * * @param array $mentionedAuthors The author list containing the current state. * * @param array $wantedAuthors The author list containing the desired state. * * @param string $path The path to relate to. * * @return array */ private function determineSuperfluous($mentionedAuthors, $wantedAuthors, $path) { $superfluous = array(); foreach (array_diff_key($mentionedAuthors, $wantedAuthors) as $key => $author) { if (!$this->config->isCopyLeftAuthor($author, $path)) { $superfluous[$key] = $author; } } return $superfluous; }
/** * Test the author mapping. * * @return void */ public function testCopyLeftAuthors() { $config = new Config(); $config->addCopyLeft('Copy Left <*****@*****.**>', 'File.php'); $config->addCopyLeft('Copy Left <*****@*****.**>', array('File2.php', '/lib/**')); $config->addCopyLeft('Copy Left2 <*****@*****.**>', 'some/dir/File4.php'); $this->assertTrue($config->isCopyLeftAuthor('Copy Left <*****@*****.**>', '/some/dir/File.php')); $this->assertTrue($config->isCopyLeftAuthor('Copy Left <*****@*****.**>', '/some/dir/File2.php')); $this->assertTrue($config->isCopyLeftAuthor('Copy Left <*****@*****.**>', '/lib/dir/File.php')); $this->assertFalse($config->isCopyLeftAuthor('Copy Left <*****@*****.**>', '/some/dir/File3.php')); $this->assertFalse($config->isCopyLeftAuthor('Unknown <*****@*****.**>', '/some/dir/File3.php')); $this->assertTrue($config->isCopyLeftAuthor('Copy Left2 <*****@*****.**>', '/lib/some/dir/File4.php')); $this->assertTrue($config->isCopyLeftAuthor('Copy Left2 <*****@*****.**>', '/some/dir/File4.php')); }
/** * {@inheritDoc} * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function execute(InputInterface $input, OutputInterface $output) { $error = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output; if (!($input->getOption('php-files') || $input->getOption('composer') || $input->getOption('bower') || $input->getOption('packages'))) { $error->writeln('<error>You must select at least one validation to run!</error>'); $error->writeln('check-author.php [--php-files] [--composer] [--bower] [--packages]'); return 1; } $config = new Config(); if (!$input->getOption('do-not-ignore-well-known-bots')) { $configFile = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'defaults' . DIRECTORY_SEPARATOR . 'ignore-well-known-bots.yml'; $config->addFromYml($configFile); } $configFile = $input->getOption('config'); if (is_file($configFile)) { $config->addFromYml($configFile); } $config->ignoreAuthors($input->getOption('ignore'))->excludePaths($input->getOption('exclude'))->includePaths(array_filter(array_map(function ($arg) { return realpath($arg); }, $input->getArgument('include')))); $diff = $input->getOption('diff'); $extractors = $this->createSourceExtractors($input, $error, $config); $gitExtractor = new GitAuthorExtractor($config, $error); $comparator = new AuthorListComparator($config, $error); $comparator->shallGeneratePatches($diff); $failed = $this->handleExtractors($extractors, $gitExtractor, $comparator); if ($failed && $diff) { $output->writeln($comparator->getPatchSet()); } return $failed ? 1 : 0; }