~ubuntu-branches/ubuntu/utopic/php-codesniffer/utopic-proposed

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.3/CodeSniffer/Reports/Svnblame.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-07-21 14:42:41 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140721144241-g4orlcuk4jzn9mhs
Tags: 1.5.3-1
* Team upload
* Focus on stable release
* Update copyright
* Bump standards version to 3.9.5
* Update Homepage
* Use ${phppear:…} instead of hardcoding them
* Run tests in dh_auto_test
* Update patch with gbp pq
* Simplify configuration installation
* Edit package.xml to move script
* Add DEP-8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Svnblame report for PHP_CodeSniffer.
 
4
 *
 
5
 * PHP version 5
 
6
 *
 
7
 * @category  PHP
 
8
 * @package   PHP_CodeSniffer
 
9
 * @author    Gabriele Santini <gsantini@sqli.com>
 
10
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
11
 * @copyright 2009-2014 SQLI <www.sqli.com>
 
12
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 
13
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 
14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
15
 */
 
16
 
 
17
/**
 
18
 * Svnblame report for PHP_CodeSniffer.
 
19
 *
 
20
 * PHP version 5
 
21
 *
 
22
 * @category  PHP
 
23
 * @package   PHP_CodeSniffer
 
24
 * @author    Gabriele Santini <gsantini@sqli.com>
 
25
 * @author    Greg Sherwood <gsherwood@squiz.net>
 
26
 * @copyright 2009-2014 SQLI <www.sqli.com>
 
27
 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
 
28
 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 
29
 * @version   Release: 1.5.3
 
30
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
31
 */
 
32
class PHP_CodeSniffer_Reports_Svnblame extends PHP_CodeSniffer_Reports_VersionControl
 
33
{
 
34
 
 
35
    /**
 
36
     * The name of the report we want in the output
 
37
     *
 
38
     * @var string
 
39
     */
 
40
    protected $reportName = 'SVN';
 
41
 
 
42
 
 
43
    /**
 
44
     * Extract the author from a blame line.
 
45
     *
 
46
     * @param string $line Line to parse.
 
47
     *
 
48
     * @return mixed string or false if impossible to recover.
 
49
     */
 
50
    protected function getAuthor($line)
 
51
    {
 
52
        $blameParts = array();
 
53
        preg_match('|\s*([^\s]+)\s+([^\s]+)|', $line, $blameParts);
 
54
 
 
55
        if (isset($blameParts[2]) === false) {
 
56
            return false;
 
57
        }
 
58
 
 
59
        return $blameParts[2];
 
60
 
 
61
    }//end getAuthor()
 
62
 
 
63
 
 
64
    /**
 
65
     * Gets the blame output.
 
66
     *
 
67
     * @param string $filename File to blame.
 
68
     *
 
69
     * @return array
 
70
     */
 
71
    protected function getBlameContent($filename)
 
72
    {
 
73
        if (PHP_CODESNIFFER_VERBOSITY > 0) {
 
74
            echo 'Getting SVN blame info for '.basename($filename).'... ';
 
75
        }
 
76
 
 
77
        $command = 'svn blame "'.$filename.'"';
 
78
        $handle  = popen($command, 'r');
 
79
        if ($handle === false) {
 
80
            echo 'ERROR: Could not execute "'.$command.'"'.PHP_EOL.PHP_EOL;
 
81
            exit(2);
 
82
        }
 
83
 
 
84
        $rawContent = stream_get_contents($handle);
 
85
        fclose($handle);
 
86
 
 
87
        if (PHP_CODESNIFFER_VERBOSITY > 0) {
 
88
            echo 'DONE'.PHP_EOL;
 
89
        }
 
90
 
 
91
        $blames = explode("\n", $rawContent);
 
92
 
 
93
        return $blames;
 
94
 
 
95
    }//end getBlameContent()
 
96
 
 
97
 
 
98
}//end class
 
99
 
 
100
?>