Completed
Pull Request — master (#19)
by
unknown
08:16
created

PropertyHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B isProperty() 0 24 1
1
<?php
2
3
namespace BestIt\Helper;
4
5
use PHP_CodeSniffer_File;
6
7
/**
8
 * Class PropertyHelper
9
 *
10
 * @package BestIt\Helper
11
 * @author Nick Lubisch <[email protected]>
12
 */
13
final class PropertyHelper
14
{
15
    /**
16
     * Determines if the given variable is a property of a class.
17
     *
18
     * @param PHP_CodeSniffer_File $file The php cs file
19
     * @param int $variablePtr Pointer to the current variable
20
     *
21
     * @return bool Indicator if the current T_VARIABLE is a property of a class
22
     */
23 26
    public static function isProperty(PHP_CodeSniffer_File $file, $variablePtr)
24
    {
25 26
        $tokens = $file->getTokens();
26
27 26
        $propertyPointer = $file->findPrevious(
28 26
            [T_STATIC, T_WHITESPACE, T_COMMENT],
29 26
            $variablePtr - 1,
30 26
            null,
31 26
            true
32
        );
33 26
        $propertyToken = $tokens[$propertyPointer];
34 26
        $propertyCode = $propertyToken['code'];
35
36 26
        return in_array(
37
            $propertyCode,
38
            [
39 26
                T_PRIVATE,
40 26
                T_PROTECTED,
41 26
                T_PUBLIC,
42 26
                T_VAR
43
            ],
44 26
            true
45
        );
46
    }
47
}
48