/** * Handle the patching cycle for a extractor. * * @param string $path The path to patch. * * @param AuthorExtractor $extractor The extractor to patch. * * @param array $wantedAuthors The authors that shall be contained in the result. * * @return bool True if the patch has been collected, false otherwise. */ private function patchExtractor($path, $extractor, $wantedAuthors) { if (!($this->diff && $extractor instanceof PatchingExtractor)) { return false; } $original = explode("\n", $extractor->getBuffer($path)); $new = explode("\n", $extractor->getBuffer($path, $wantedAuthors)); $diff = new \Diff($original, $new); $patch = $diff->render($this->diff); if (empty($patch)) { return false; } $patchFile = $path; foreach ($this->config->getIncludedPaths() as $prefix) { $prefixLength = strlen($prefix); if (substr($path, 0, $prefixLength) === $prefix) { $patchFile = substr($path, $prefixLength); if ($patchFile[0] == '/') { $patchFile = substr($patchFile, 1); } break; } } $this->patchSet[] = 'diff ' . $patchFile . ' ' . $patchFile . "\n" . '--- ' . $patchFile . "\n" . '+++ ' . $patchFile . "\n" . $patch; return true; }
/** * 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; }