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

PHPCSStandards / PHP_CodeSniffer / 15253068925

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

Pull #1106

github

web-flow
Merge bfa18e7f8 into caf806050
Pull Request #1106: Declare dependency on bcmath extension

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

88.89
/src/Standards/Squiz/Sniffs/Scope/MemberVarScopeSniff.php
1
<?php
2
/**
3
 * Verifies that class members have scope modifiers.
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\Standards\Squiz\Sniffs\Scope;
11

12
use PHP_CodeSniffer\Exceptions\RuntimeException;
13
use PHP_CodeSniffer\Files\File;
14
use PHP_CodeSniffer\Sniffs\AbstractScopeSniff;
15
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
16
use PHP_CodeSniffer\Util\Tokens;
17

18
class MemberVarScopeSniff extends AbstractVariableSniff
19
{
20

21

22
    /**
23
     * Only listen to variables within OO scopes.
24
     */
25
    public function __construct()
3✔
26
    {
27
        AbstractScopeSniff::__construct(Tokens::OO_SCOPE_TOKENS, [T_VARIABLE], false);
3✔
28

29
    }//end __construct()
1✔
30

31

32
    /**
33
     * Processes the function tokens within the class.
34
     *
35
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
36
     * @param int                         $stackPtr  The position where the token was found.
37
     *
38
     * @return void
39
     */
40
    protected function processMemberVar(File $phpcsFile, $stackPtr)
3✔
41
    {
42
        try {
43
            $properties = $phpcsFile->getMemberProperties($stackPtr);
3✔
44
        } catch (RuntimeException $e) {
3✔
45
            // Parse error: property in enum. Ignore.
46
            return;
3✔
47
        }
48

49
        if ($properties['scope_specified'] !== false) {
3✔
50
            return;
3✔
51
        }
52

53
        $tokens = $phpcsFile->getTokens();
3✔
54
        $error  = 'Scope modifier not specified for member variable "%s"';
3✔
55
        $data   = [$tokens[$stackPtr]['content']];
3✔
56
        $phpcsFile->addError($error, $stackPtr, 'Missing', $data);
3✔
57

58
    }//end processMemberVar()
1✔
59

60

61
    /**
62
     * Processes normal variables.
63
     *
64
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
65
     * @param int                         $stackPtr  The position where the token was found.
66
     *
67
     * @return void
68
     */
69
    protected function processVariable(File $phpcsFile, $stackPtr)
3✔
70
    {
71
        /*
72
            We don't care about normal variables.
73
        */
74

75
    }//end processVariable()
3✔
76

77

78
    /**
79
     * Processes variables in double quoted strings.
80
     *
81
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
82
     * @param int                         $stackPtr  The position where the token was found.
83
     *
84
     * @return void
85
     */
86
    protected function processVariableInString(File $phpcsFile, $stackPtr)
×
87
    {
88
        /*
89
            We don't care about normal variables.
90
        */
91

92
    }//end processVariableInString()
×
93

94

95
}//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