Completed
Push — master ( c6357c...5bad31 )
by Juliette
9s
created

TokenScopeTest::dataTokenHasScope()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 37
rs 8.8571
cc 1
eloc 25
nc 1
nop 0
1
<?php
2
/**
3
 * Token scope test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Token scope function tests
11
 *
12
 * @uses    BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class TokenScopeTest extends BaseAbstractClassMethodTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
19
    public $filename = 'sniff-examples/utility-functions/token_has_scope.php';
20
21
    /**
22
     * testTokenHasScope
23
     *
24
     * @group utilityFunctions
25
     *
26
     * @dataProvider dataTokenHasScope
27
     *
28
     * @param int    $stackPtr Stack pointer for an arbitrary token in the test file.
29
     * @param string $expected The expected boolean return value.
30
     */
31
    public function testTokenHasScope($stackPtr, $expected, $validTokens = null)
32
    {
33
        $result = $this->helperClass->tokenHasScope($this->_phpcsFile, $stackPtr, $validTokens);
34
        $this->assertSame($expected, $result);
35
    }
36
37
    /**
38
     * dataTokenHasScope
39
     *
40
     * @see testTokenHasScope()
41
     *
42
     * @return array
43
     */
44
    public function dataTokenHasScope()
45
    {
46
        return array(
47
            // No scope.
48
            array(2, false), // $var
49
50
            // Various scopes.
51
            array(23, true), // echo within if
52
            array(23, true, array( T_IF ) ), // echo within if
53
            array(23, false, array( T_SWITCH ) ), // echo within if
54
55
            array(45, true), // echo within else-if
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
            array(45, true, array( T_ELSEIF ) ), // echo within else-if
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
            array(45, false, array( T_IF ) ), // echo within else-if
1 ignored issue
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
59
            array(57, true), // echo within else
60
            array(86, true), // echo within for
61
            array(107, true), // echo within foreach
62
63
            array(123, true), // case within switch
64
            array(123, true, array(T_SWITCH)), // case within switch
65
            array(123, false, array(T_CASE)), // case within switch
66
67
            array(129, true), // echo within case within switch
68
            array(129, true, array(T_SWITCH)), // echo within case within switch
69
            array(129, true, array(T_CASE)), // echo within case within switch
70
            array(129, true, array(T_SWITCH, T_CASE)), // echo within case within switch
71
            array(129, true, array(T_SWITCH, T_IF)), // echo within case within switch
72
            array(129, false, array(T_ELSEIF, T_IF)), // echo within case within switch
73
74
            array(139, true), // default within switch
75
            array(143, true), // echo within default within switch
76
77
            array(164, true), // echo within function
78
            array(164, true, array(T_FUNCTION)), // echo within function
79
        );
80
    }
81
82
    /**
83
     * testInClassScope
84
     *
85
     * @group utilityFunctions
86
     *
87
     * @dataProvider dataInClassScope
88
     *
89
     * @param int    $stackPtr Stack pointer for an arbitrary token in the test file.
90
     * @param string $expected The expected boolean return value.
91
     */
92
    public function testInClassScope($stackPtr, $expected)
93
    {
94
        $result = $this->helperClass->inClassScope($this->_phpcsFile, $stackPtr);
95
        $this->assertSame($expected, $result);
96
    }
97
98
    /**
99
     * dataInClassScope
100
     *
101
     * @see testInClassScope()
102
     *
103
     * @return array
104
     */
105
    public function dataInClassScope()
106
    {
107
        return array(
108
            array(181, true), // $property
109
            array(185, true), // function
110
            array(202, false), // function
111
            array(220, true), // function
112
        );
113
    }
114
115
}
116