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

MissingBreakStatement::testValidSwitch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 14
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 74.

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 MissingBreakStatement
6
{
7
    /**
8
     * @return string
9
     */
10
    public function testMissingBreakStatement()
11
    {
12
        $value = 'default';
13
14
        switch ('hello') {
15
            case 'hello':
16
                return 'world';
17
            case 'bar':
18
                $value = 'baz';
19
                break;
20
            case 'whoops':
0 ignored issues
show
Coding Style introduced by
There must be a comment when fall-through is intentional in a non-empty case body
Loading history...
21
                $value = 'missing "break" statement here';
22
            case 'foo':
23
                $value = 'bar';
24
                break;
25
            case 'error':
26
                $value = 'an empty return looks a bit weird in a switch';
27
                return;
28
            default:
29
                return 'what?';
30
        }
31
32
        return $value;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function testValidSwitch()
39
    {
40
        switch ('hello') {
41
            case 'hello':
42
                return 'world';
43
            case 'bar':
44
                $value = 'baz';
45
                break;
46
            default:
47
                return 'what?';
48
        }
49
50
        return $value;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function testValidSwitchWithSeveralJoinedCases()
57
    {
58
        switch ('hello') {
59
            case 'hello':
60
            case 'bar':
61
                $value = 'baz';
62
                break;
63
            case 'foo':
64
                $value = 'yay!';
65
                break;
66
            default:
67
                return 'what?';
68
        }
69
70
        return $value;
71
    }
72
}
73
?>
74
----------------------------
75
[
76
    {
77
        "type":"missing_break_statement",
78
        "message":"Missing \"break\" statement",
79
        "file":"MissingBreakStatement.php",
80
        "line":19
81
    },
82
83
    {
84
        "type":"missing_break_statement",
85
        "message":"Empty return in \"case\" statement",
86
        "file":"MissingBreakStatement.php",
87
        "line":26
88
    }
89
]
90