Failed Conditions
Push — master ( c7ef78...c451af )
by Alexander
02:24
created

CodingStandard/Tests/Formatting/BlankLineBeforeReturnUnitTest.inc::loopTesting()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 21
rs 8.7624
1
<?php
2
function validNoBlankAfterScopeOpen()
3
{
4
    return;
5
}
6
7
function invalidBlankAfterScopeOpenOne()
8
{
9
10
    return;
11
}
12
13
function invalidBlankAfterScopeOpenTwo()
14
{
15
16
17
    return;
18
}
19
20
function validFunctionReturnThree()
21
{
22
    echo '';
23
24
    return;
25
}
26
27
function invalidFunctionReturnOne()
28
{
29
    echo '';
30
    return;
31
}
32
33
function validSwitchStatement()
34
{
35
    switch ($condition) {
0 ignored issues
show
Bug introduced by
The variable $condition does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
        case 'foo':
37
            return true;
38
39
        default:
40
            return false;
41
    }
42
}
43
44
function invalidSwitchStatementOne()
45
{
46
    switch ($condition) {
0 ignored issues
show
Bug introduced by
The variable $condition does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
47
        case 'foo':
48
49
            return true;
50
51
        default:
52
53
            return false;
54
    }
55
}
56
57
function invalidSwitchStatementTwo()
58
{
59
    switch ($condition) {
0 ignored issues
show
Bug introduced by
The variable $condition does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
60
        case 'foo':
61
62
            return true;
63
64
        default:
65
            return false;
66
    }
67
}
68
69
function invalidSwitchStatementThree()
70
{
71
    switch ($condition) {
0 ignored issues
show
Bug introduced by
The variable $condition does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
72
        case 'foo':
73
            if ($something) {
0 ignored issues
show
Bug introduced by
The variable $something does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
74
                return false;
75
            }
76
            return true;
77
78
        default:
79
80
            return false;
81
    }
82
}
83
84
function validReturnFromIf()
85
{
86
    if ($condition) {
87
        return true;
88
	} elseif ($condition) {
0 ignored issues
show
Bug introduced by
The variable $condition does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
89
        return false;
90
    }
91
    else {
92
        return 5;
93
    }
94
}
95
96
function tooMuchBlankLinesOne()
97
{
98
    echo "";
99
100
101
    return;
102
}
103
104
function loopTesting()
105
{
106
	for ($i = 0; $i < 5; $i++) {
0 ignored issues
show
Unused Code introduced by
$i++; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
107
        return 'ok';
108
109
        if (false) {
0 ignored issues
show
Unused Code introduced by
if (false) { return 'ok'; } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
110
            return 'ok';
111
        }
112
        return true;
113
    }
114
115
    do {
0 ignored issues
show
Unused Code introduced by
do { return $ret; } while (true); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
116
117
        return $ret;
0 ignored issues
show
Bug introduced by
The variable $ret does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
118
    } while (true);
119
120
    foreach ($test as $key) {
121
        return;
122
    }
123
124
}
125
126
function validWithPrecedingInlineComment()
127
{
128
    // This is allowed.
129
    return;
130
}
131
132
function invalidWithPrecedingInlineComment()
133
{
134
135
    // This is not allowed.
136
    return;
137
}
138
139
function invalidWithAlmostPrecedingInlineComment()
140
{
141
    // This is not allowed.
142
143
    return;
144
}
145