• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCSStandards / PHP_CodeSniffer / 15253296250

26 May 2025 11:55AM UTC coverage: 78.632% (+0.3%) from 78.375%
15253296250

Pull #1105

github

web-flow
Merge d9441d98f into caf806050
Pull Request #1105: Skip tests when 'git' command is not available

19665 of 25009 relevant lines covered (78.63%)

88.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/Filters/GitModified.php
1
<?php
2
/**
3
 * A filter to only include files that have been modified or added in a Git repository.
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/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
 */
9

10
namespace PHP_CodeSniffer\Filters;
11

12
use PHP_CodeSniffer\Util\Common;
13

14
class GitModified extends ExactMatch
15
{
16

17

18
    /**
19
     * Get a list of file paths to exclude.
20
     *
21
     * @since 3.9.0 Replaces the `getBlacklist()` method, which was removed in PHPCS 4.0.0.
22
     *
23
     * @return array
24
     */
25
    protected function getDisallowedFiles()
24✔
26
    {
27
        return [];
24✔
28

29
    }//end getDisallowedFiles()
30

31

32
    /**
33
     * Get a list of file paths to include.
34
     *
35
     * @since 3.9.0 Replaces the `getWhitelist()` method, which was removed in PHPCS 4.0.0.
36
     *
37
     * @return array
38
     */
39
    protected function getAllowedFiles()
24✔
40
    {
41
        $modified = [];
24✔
42

43
        $cmd    = 'git ls-files -o -m --exclude-standard -- '.escapeshellarg($this->basedir);
24✔
44
        $output = $this->exec($cmd);
24✔
45

46
        $basedir = $this->basedir;
24✔
47
        if (is_dir($basedir) === false) {
24✔
48
            $basedir = dirname($basedir);
3✔
49
        }
50

51
        foreach ($output as $path) {
24✔
52
            $path = Common::realpath($path);
21✔
53

54
            if ($path === false) {
21✔
55
                continue;
3✔
56
            }
57

58
            do {
59
                $modified[$path] = true;
18✔
60
                $path            = dirname($path);
18✔
61
            } while ($path !== $basedir);
18✔
62
        }
63

64
        return $modified;
24✔
65

66
    }//end getAllowedFiles()
67

68

69
    /**
70
     * Execute an external command.
71
     *
72
     * {@internal This method is only needed to allow for mocking the return value
73
     * to test the class logic.}
74
     *
75
     * @param string $cmd Command.
76
     *
77
     * @return array
78
     */
79
    protected function exec($cmd)
6✔
80
    {
81
        $output   = [];
6✔
82
        $lastLine = exec($cmd, $output);
6✔
83
        if ($lastLine === false) {
6✔
84
            return [];
×
85
        }
86

87
        return $output;
6✔
88

89
    }//end exec()
90

91

92
}//end class
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc