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

MyClass   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 10
rs 10
wmc 1
lcom 0
cbo 0
1
<?php
2
// Some code goes here.
3
$code = 'hello';
4
5
// This comment contains # multiple
6
// hash signs (#).
7
$code = 'hello';
8
9
/*
10
 * Here is a small function comment.
11
 */
12
function test()
13
{
14
    // Some code goes here.
15
    $code = 'hello';
0 ignored issues
show
Unused Code introduced by
$code is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
17
    # This comment is banned.
18
    $code = 'hello';
0 ignored issues
show
Unused Code introduced by
$code is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
19
20
}//end test()
21
22
/*
23
    A longer comment goes here.
24
    It spans multiple lines.
25
*/
26
27
# This is a long comment
28
# that is banned.
29
30
31
32
// some code goes here!
33
34
// This comment contains # multiple
35
// hash signs (#) but no
36
// full stop
37
$code = 'hello';
38
39
/*
40
 * Here is a small function comment
41
 */
42
function test()
0 ignored issues
show
Best Practice introduced by
The function test() has been defined more than once; this definition is ignored, only the first definition in this file (L12-20) is considered.

This check looks for functions that have already been defined in the same file.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
43
{
44
    // Some code goes here
45
46
}//end test()
47
48
/*
49
    A longer comment goes here.
50
    It spans multiple lines!!
51
    Or does it?
52
*/
53
54
// this is a simple multi-line
55
// comment!
56
$code = 'hello';
57
58
//This is not valid.
59
$code = 'hello';
60
61
//  Neither is this!
62
$code = 'hello';
63
64
//
65
$code = 'hello';
66
67
/** Neither is this! **/
68
$code = 'hello';
69
70
class MyClass
71
{
72
    /**
73
     * Represents a left orientation for the widget.
74
     *
75
     * @var   integer
76
     * @since 4.0.0
77
     */
78
    const LEFT = 1;
79
}
80
81
/**
82
 * Comment should be ignored.
83
 *
84
 */
85
final class MyClass
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type MyClass has been defined more than once; this definition is ignored, only the first definition in this file (L70-79) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
86
{
87
    /**
88
     * Comment should be ignored.
89
     *
90
     */
91
    final public function test() {}
92
}
93
94
// 这是一条测试评论
95
//     -> One
96
//         -> One.One
97
//     -> Two
98
99
/*
100
    Here is some inline example code:
101
        -> One
102
            -> One.One
103
        -> Two
104
*/
105
106
/**
107
 * Comment should be ignored in PHP 5.4.
108
 *
109
 */
110
trait MyTrait {
111
112
}
113
114
// 5.this is a simple multi-line
115
// comment!
116
$code = 'hello';
117
118
/** @var \stdClass $some_var */
119
$some_var = 'Object';
120
121
$foo = 'foo'; // Var set to foo.
122
123
echo $foo;
124
125
126
class SomeClass
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type SomeClass has been defined more than once; this definition is ignored, only the first definition in CodingStandard/Tests/Cla...DeclarationUnitTest.inc (L3-7) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
127
{
128
    function someMethod()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
129
    {
130
//      This is comment indented with spaces.
131
        $a = 5;
0 ignored issues
show
Unused Code introduced by
$a is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
132
133
//		This is comment indented with tabs.
134
		$a = 5;
0 ignored issues
show
Unused Code introduced by
$a is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
135
    }
136
}
137
138
// 'var' => 'ok',
139
$code = 5;
140
141
// $This = OK;
142
$code = 5;
143
144
/** @type \stdClass $some_var */
145
$some_var = 'Object';
146
147
148
if ($b) {
149
    $c = 'd';
150
}
151
// Comment.
152
153
$next_code = 5;
154
155
156
// comment starts with lowercase letter - bad.
157
$a = 1;
158
159
// [comment starts with non-letter - good.
160
$a = 1;
161
162
// 5comment starts with non-letter - good.
163
$a = 1;
164
165
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
166