3
* Mercurial report for PHP_CodeSniffer.
8
* @package PHP_CodeSniffer
9
* @author Ben Selby <benmatselby@gmail.com>
10
* @copyright 2009-2014 SQLI <www.sqli.com>
11
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
12
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
13
* @link http://pear.php.net/package/PHP_CodeSniffer
17
* Mercurial report for PHP_CodeSniffer.
22
* @package PHP_CodeSniffer
23
* @author Ben Selby <benmatselby@gmail.com>
24
* @copyright 2009-2014 SQLI <www.sqli.com>
25
* @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
26
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
27
* @version Release: 1.5.5
28
* @link http://pear.php.net/package/PHP_CodeSniffer
30
class PHP_CodeSniffer_Reports_Hgblame extends PHP_CodeSniffer_Reports_VersionControl
34
* The name of the report we want in the output
38
protected $reportName = 'MERCURIAL';
42
* Extract the author from a blame line.
44
* @param string $line Line to parse.
46
* @return mixed string or false if impossible to recover.
48
protected function getAuthor($line)
50
$blameParts = array();
51
$line = preg_replace('|\s+|', ' ', $line);
54
'|(.+[0-9]{2}:[0-9]{2}:[0-9]{2}\s[0-9]{4}\s.[0-9]{4}:)|',
59
if (isset($blameParts[0]) === false) {
63
$parts = explode(' ', $blameParts[0]);
65
if (count($parts) < 6) {
69
$parts = array_slice($parts, 0, (count($parts) - 6));
71
return trim(preg_replace('|<.+>|', '', implode($parts, ' ')));
77
* Gets the blame output.
79
* @param string $filename File to blame.
83
protected function getBlameContent($filename)
87
if (PHP_CODESNIFFER_VERBOSITY > 0) {
88
echo 'Getting MERCURIAL blame info for '.basename($filename).'... ';
91
$fileParts = explode(DIRECTORY_SEPARATOR, $filename);
94
while (empty($fileParts) === false) {
95
array_pop($fileParts);
96
$location = implode($fileParts, DIRECTORY_SEPARATOR);
97
if (is_dir($location.DIRECTORY_SEPARATOR.'.hg') === true) {
103
if ($found === true) {
106
echo 'ERROR: Could not locate .hg directory '.PHP_EOL.PHP_EOL;
110
$command = 'hg blame -u -d -v "'.$filename.'"';
111
$handle = popen($command, 'r');
112
if ($handle === false) {
113
echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
117
$rawContent = stream_get_contents($handle);
120
if (PHP_CODESNIFFER_VERBOSITY > 0) {
124
$blames = explode("\n", $rawContent);
129
}//end getBlameContent()