Completed
Push — master ( d8f6c8...9bf369 )
by Дмитрий
10s
created

UnexpectedUseOfThis::thisInCatch()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 5 and the first side effect is on line 68.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Tests\Compiling\Statements;
4
5
class UnexpectedUseOfThis
6
{
7
    /**
8
     * @return string
9
     */
10
    public function thisAsArgument($this)
11
    {
12
        return 'Cannot use $this as parameter';
13
    }
14
15
    /**
16
     * @return string
17
     */
18
    public function thisInCatch()
19
    {
20
        try {
21
            throw new \LogicException();
22
        } catch (\Exception $this) {
23
            return 'Fatal error: Cannot re-assign $this';
24
        }
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function thisAsLoopVariable()
31
    {
32
        foreach (['foo'] as $this) {
33
            return 'Fatal error: Cannot re-assign $this';
34
        }
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function thisAsStaticVariable()
41
    {
42
        static $this;
43
44
        return 'Fatal error: Cannot use $this as static variable';
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function thisAsGlobalVariable()
51
    {
52
        global $this;
53
54
        return 'Fatal error: Cannot use $this as global variable';
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function unsetThis()
61
    {
62
        unset($this);
63
64
        return 'Fatal error: Cannot unset $this';
65
    }
66
}
67
?>
68
----------------------------
69
[
70
    {
71
        "type":"unexpected_use.this",
72
        "message":"Method thisAsArgument can not have a parameter named \"this\".",
73
        "file":"UnexpectedUseOfThis.php",
74
        "line":9
75
    },
76
    {
77
        "type":"unexpected_use.this",
78
        "message":"Catch block can not have a catch variable named \"this\".",
79
        "file":"UnexpectedUseOfThis.php",
80
        "line":21
81
    },
82
    {
83
        "type":"unexpected_use.this",
84
        "message":"Foreach loop can not use a value variable named \"this\".",
85
        "file":"UnexpectedUseOfThis.php",
86
        "line":31
87
    },
88
    {
89
        "type":"unexpected_use.this",
90
        "message":"Can not declare a static variable named \"this\".",
91
        "file":"UnexpectedUseOfThis.php",
92
        "line":41
93
    },
94
    {
95
        "type":"unexpected_use.this",
96
        "message":"Can not declare a global variable named \"this\".",
97
        "file":"UnexpectedUseOfThis.php",
98
        "line":51
99
    },
100
    {
101
        "type":"unexpected_use.this",
102
        "message":"Can not unset $this.",
103
        "file":"UnexpectedUseOfThis.php",
104
        "line":61
105
    }
106
]
107