annotate vendor/squizlabs/php_codesniffer/src/Reports/Svnblame.php @ 5:12f9dff5fda9 tip

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