Passed
Pull Request — master (#19)
by
unknown
02:19
created

PropertyHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 51
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B isProperty() 0 24 1
1
<?php
2
3
namespace BestIt\CodeSniffer\Helper;
4
5
use BestIt\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
     * The wrapped PHP_CodeSniffer_File
17
     *
18
     * @var File
19
     */
20
    private $file;
21
22
    /**
23
     * PropertyHelper constructor.
24
     *
25
     * @param File $file The wrapped PHP_CodeSniffer_File
26
     */
27 109
    public function __construct(File $file)
28
    {
29 109
        $this->file = $file;
30 109
    }
31
32
    /**
33
     * Determines if the given variable is a property of a class.
34
     *
35
     * @param int $variablePtr Pointer to the current variable
36
     *
37
     * @return bool Indicator if the current T_VARIABLE is a property of a class
38
     */
39 26
    public function isProperty($variablePtr)
40
    {
41 26
        $tokens = $this->file->getTokens();
42
43 26
        $propertyPointer = $this->file->findPrevious(
44 26
            [T_STATIC, T_WHITESPACE, T_COMMENT],
45 26
            $variablePtr - 1,
46 26
            null,
47 26
            true
48
        );
49 26
        $propertyToken = $tokens[$propertyPointer];
50 26
        $propertyCode = $propertyToken['code'];
51
52 26
        return in_array(
53
            $propertyCode,
54
            [
55 26
                T_PRIVATE,
56 26
                T_PROTECTED,
57 26
                T_PUBLIC,
58 26
                T_VAR
59
            ],
60 26
            true
61
        );
62
    }
63
}
64