comparison vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
1 <?php
2 /**
3 * SVN blame report for PHP_CodeSniffer.
4 *
5 * @author Greg Sherwood <gsherwood@squiz.net>
6 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8 */
9
10 namespace PHP_CodeSniffer\Reports;
11
12 use PHP_CodeSniffer\Exceptions\DeepExitException;
13
14 class Svnblame extends VersionControl
15 {
16
17 /**
18 * The name of the report we want in the output
19 *
20 * @var string
21 */
22 protected $reportName = 'SVN';
23
24
25 /**
26 * Extract the author from a blame line.
27 *
28 * @param string $line Line to parse.
29 *
30 * @return mixed string or false if impossible to recover.
31 */
32 protected function getAuthor($line)
33 {
34 $blameParts = [];
35 preg_match('|\s*([^\s]+)\s+([^\s]+)|', $line, $blameParts);
36
37 if (isset($blameParts[2]) === false) {
38 return false;
39 }
40
41 return $blameParts[2];
42
43 }//end getAuthor()
44
45
46 /**
47 * Gets the blame output.
48 *
49 * @param string $filename File to blame.
50 *
51 * @return array
52 */
53 protected function getBlameContent($filename)
54 {
55 $command = 'svn blame "'.$filename.'" 2>&1';
56 $handle = popen($command, 'r');
57 if ($handle === false) {
58 $error = 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
59 throw new DeepExitException($error, 3);
60 }
61
62 $rawContent = stream_get_contents($handle);
63 fclose($handle);
64
65 $blames = explode("\n", $rawContent);
66
67 return $blames;
68
69 }//end getBlameContent()
70
71
72 }//end class