Chris@17: Chris@17: * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) Chris@17: * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence Chris@17: */ Chris@17: Chris@17: namespace PHP_CodeSniffer\Reports; Chris@17: Chris@17: use PHP_CodeSniffer\Exceptions\DeepExitException; Chris@17: Chris@17: class Svnblame extends VersionControl Chris@17: { Chris@17: Chris@17: /** Chris@17: * The name of the report we want in the output Chris@17: * Chris@17: * @var string Chris@17: */ Chris@17: protected $reportName = 'SVN'; Chris@17: Chris@17: Chris@17: /** Chris@17: * Extract the author from a blame line. Chris@17: * Chris@17: * @param string $line Line to parse. Chris@17: * Chris@17: * @return mixed string or false if impossible to recover. Chris@17: */ Chris@17: protected function getAuthor($line) Chris@17: { Chris@17: $blameParts = []; Chris@17: preg_match('|\s*([^\s]+)\s+([^\s]+)|', $line, $blameParts); Chris@17: Chris@17: if (isset($blameParts[2]) === false) { Chris@17: return false; Chris@17: } Chris@17: Chris@17: return $blameParts[2]; Chris@17: Chris@17: }//end getAuthor() Chris@17: Chris@17: Chris@17: /** Chris@17: * Gets the blame output. Chris@17: * Chris@17: * @param string $filename File to blame. Chris@17: * Chris@17: * @return array Chris@17: */ Chris@17: protected function getBlameContent($filename) Chris@17: { Chris@17: $command = 'svn blame "'.$filename.'" 2>&1'; Chris@17: $handle = popen($command, 'r'); Chris@17: if ($handle === false) { Chris@17: $error = 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL; Chris@17: throw new DeepExitException($error, 3); Chris@17: } Chris@17: Chris@17: $rawContent = stream_get_contents($handle); Chris@17: fclose($handle); Chris@17: Chris@17: $blames = explode("\n", $rawContent); Chris@17: Chris@17: return $blames; Chris@17: Chris@17: }//end getBlameContent() Chris@17: Chris@17: Chris@17: }//end class