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

sirbrillig / phpcs-variable-analysis / 13853172128

14 Mar 2025 08:59AM UTC coverage: 93.812%. Remained the same
13853172128

Pull #350

github

jrfnl
GH Actions: use the xmllint-validate action runner

Instead of doing all the installation steps for xmllint validation in the workflow, use the :sparkles: new dedicated `phpcsstandards/xmllint-validate` action runner instead.

Ref: https://github.com/marketplace/actions/xmllint-validate
Pull Request #350: GH Actions: use the xmllint-validate action runner

1880 of 2004 relevant lines covered (93.81%)

137.02 hits per line

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

91.18
/VariableAnalysis/Lib/ScopeManager.php
1
<?php
2

3
namespace VariableAnalysis\Lib;
4

5
use VariableAnalysis\Lib\ScopeInfo;
6
use VariableAnalysis\Lib\Helpers;
7
use PHP_CodeSniffer\Files\File;
8

9
class ScopeManager
10
{
11
        /**
12
         * An associative array of a list of token index pairs which start and end
13
         * scopes and will be used to check for unused variables.
14
         *
15
         * The outer array of scopes is keyed by a string containing the filename.
16
         * The inner array of scopes in keyed by the scope start token index.
17
         *
18
         * @var array<string, array<int, ScopeInfo>>
19
         */
20
        private $scopes = [];
21

22
        /**
23
         * Add a scope's start and end index to our record for the file.
24
         *
25
         * @param File $phpcsFile
26
         * @param int  $scopeStartIndex
27
         *
28
         * @return ScopeInfo
29
         */
30
        public function recordScopeStartAndEnd(File $phpcsFile, $scopeStartIndex)
352✔
31
        {
32
                $scopeEndIndex = Helpers::getScopeCloseForScopeOpen($phpcsFile, $scopeStartIndex);
352✔
33
                $filename = $phpcsFile->getFilename();
352✔
34
                if (! isset($this->scopes[$filename])) {
352✔
35
                        $this->scopes[$filename] = [];
352✔
36
                }
176✔
37
                Helpers::debug('recording scope for file', $filename, 'start/end', $scopeStartIndex, $scopeEndIndex);
352✔
38
                $scope = new ScopeInfo($scopeStartIndex, $scopeEndIndex);
352✔
39
                $this->scopes[$filename][$scopeStartIndex] = $scope;
352✔
40
                return $scope;
352✔
41
        }
42

43
        /**
44
         * Return the scopes for a file.
45
         *
46
         * @param string $filename
47
         *
48
         * @return ScopeInfo[]
49
         */
50
        public function getScopesForFilename($filename)
352✔
51
        {
52
                if (empty($this->scopes[$filename])) {
352✔
53
                        return [];
352✔
54
                }
55
                return array_values($this->scopes[$filename]);
352✔
56
        }
57

58
        /**
59
         * Return the scope for a scope start index.
60
         *
61
         * @param string $filename
62
         * @param int    $scopeStartIndex
63
         *
64
         * @return ScopeInfo|null
65
         */
66
        public function getScopeForScopeStart($filename, $scopeStartIndex)
352✔
67
        {
68
                if (empty($this->scopes[$filename][$scopeStartIndex])) {
352✔
69
                        return null;
×
70
                }
71
                return $this->scopes[$filename][$scopeStartIndex];
352✔
72
        }
73

74
        /**
75
         * Find scopes closed by a scope close index.
76
         *
77
         * @param string $filename
78
         * @param int    $scopeEndIndex
79
         *
80
         * @return ScopeInfo[]
81
         */
82
        public function getScopesForScopeEnd($filename, $scopeEndIndex)
352✔
83
        {
84
                $scopePairsForFile = $this->getScopesForFilename($filename);
352✔
85
                $scopeIndicesThisCloses = array_reduce(
352✔
86
                        $scopePairsForFile,
352✔
87
                        /**
88
                         * @param ScopeInfo[] $found
89
                         * @param ScopeInfo   $scope
90
                         *
91
                         * @return ScopeInfo[]
92
                         */
93
                        function ($found, $scope) use ($scopeEndIndex) {
352✔
94
                                if (! is_int($scope->scopeEndIndex)) {
352✔
95
                                        Helpers::debug('No scope closer found for scope start', $scope->scopeStartIndex);
×
96
                                        return $found;
×
97
                                }
98

99
                                if ($scopeEndIndex === $scope->scopeEndIndex) {
352✔
100
                                        $found[] = $scope;
352✔
101
                                }
176✔
102
                                return $found;
352✔
103
                        },
352✔
104
                        []
352✔
105
                );
352✔
106
                return $scopeIndicesThisCloses;
352✔
107
        }
108
}
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