PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file Svnblame.php

Documentation is available at Svnblame.php

  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. class Svnblame extends VersionControl
  13. {
  14.  
  15.     /**
  16.      * The name of the report we want in the output
  17.      *
  18.      * @var string 
  19.      */
  20.     protected $reportName 'SVN';
  21.  
  22.  
  23.     /**
  24.      * Extract the author from a blame line.
  25.      *
  26.      * @param string $line Line to parse.
  27.      *
  28.      * @return mixed string or false if impossible to recover.
  29.      */
  30.     protected function getAuthor($line)
  31.     {
  32.         $blameParts = array();
  33.         preg_match('|\s*([^\s]+)\s+([^\s]+)|'$line$blameParts);
  34.  
  35.         if (isset($blameParts[2]=== false{
  36.             return false;
  37.         }
  38.  
  39.         return $blameParts[2];
  40.  
  41.     }//end getAuthor()
  42.  
  43.  
  44.     /**
  45.      * Gets the blame output.
  46.      *
  47.      * @param string $filename File to blame.
  48.      *
  49.      * @return array 
  50.      */
  51.     protected function getBlameContent($filename)
  52.     {
  53.         if (PHP_CODESNIFFER_VERBOSITY > 0{
  54.             echo 'Getting SVN blame info for '.basename($filename).'... ';
  55.         }
  56.  
  57.         $command 'svn blame "'.$filename.'" 2>&1';
  58.         $handle  popen($command'r');
  59.         if ($handle === false{
  60.             echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
  61.             exit(3);
  62.         }
  63.  
  64.         $rawContent stream_get_contents($handle);
  65.         fclose($handle);
  66.  
  67.         if (PHP_CODESNIFFER_VERBOSITY > 0{
  68.             echo 'DONE'.PHP_EOL;
  69.         }
  70.  
  71.         $blames explode("\n"$rawContent);
  72.  
  73.         return $blames;
  74.  
  75.     }//end getBlameContent()
  76.  
  77.  
  78. }//end class

Documentation generated on Mon, 11 Mar 2019 14:49:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.