1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2011-2014 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class bad_code {
var $a = 1; // should complain about equals alignment
var $bc = 2;
var $a = 1; // should not complain
var $bcc = 2;
var $a= 1; // should complain about missing space before equal
var $b= 2; // should complain about missing space before equal
function bad_brace () { // should complain about the brace
$this->a = 10;
if ($this->a == 10) {
$r = 1;
} elseif ($this->a == 9) {
$r = 2;
} else {
$r = 3;
}
if ($this->a == 10)
{ // should complain about the brace
$r = 1;
} // should complain about the brace
elseif ($this->a == 9) {
$r = 2;
} // should complain about the brace
else
{ // should complain about the brace
$r = 3;
}
do {
echo "nothing";
} while (TRUE); // should not complain
}
function bad_indent ()
{
$b = 1; // should not complain
$b = 2; // should complain about indentation
$b = 3; // should complain about indentation
$c = "4"; // should complain about indentation
if (TRUE) {
$b = 2; // should complain about indentation
} else {
$b = "5"; // should complain about indentation
}// should complain about indentation
}
function bad_line_length ()
{
$s = "Something short"; // should not complain
$s = "Something very long, this should warn about line length longer than 80";
$s = "Something very very long, this should trigger an error about line length that is too big, because it is very long";
$s = "Something not very long"; // should not complain, as it is the comment that goes too far.
}
function bad_spaces ($a,$b) // should complain
{
$a=1; // should complain
$a= 1; // should complain
$a =1; // should complain
$a = 1; // should not complain
$a = 1; // should not complain
$ab = 1; // should not complain
$this-> a = 1; // should complain
$this ->a = 1; // should complain
$this -> a = 1; // should complain
$this->a = 1; // should not complain
if(TRUE) { // should complain
$a = 1;
}elseif(FALSE) { // should complain
$a = 1;
}else { // should complain
$a = 1;
}
if (FALSE){ // should complain
$a = 1;
} elseif($a == TRUE) { // should complain
$a = 1;
} else{ // should complain
$a = 1;
}
if (TRUE) { // good one
$a = 1;
} elseif ($a == FALSE) {
$a = 1;
} else {
$a = 1;
}
if (isset($a)) { // should not complain
$a = 1;
}
if (isset($a) &&
isset($b)) { // should not complain
$a = 1;
}
some_function($a,$b); // should complain
some_function($a, $b); // should not complain
some_function($a, $b); // should not complain
}
function bad_constant ()
{
$b = FALSE; // should not complain
$b = False; // should complain
$b = false; // should complain
$b = TRUE; // should not complain
$b = True; // should complain
$b = true; // should complain
$b = NULL; // should not complain
$b = Null; // should complain
$b = null; // should complain
}
function bad_comment ()
{
# should complain
}
function bad_return ()
{
return ($something); // should complain
$a = 4; // should complain : not executed code
}
function other_bad_return ()
{
return($something); // should complain
}
function yet_another_bad_return ()
{
return (fake_function($something == "something")); // should complain
}
function yet_another_bad_return_bis ()
{
return$something; // should complain
}
function good_return ()
{
return ($something == "something"); // should not complain
}
function other_good_return ()
{
return $something; // should not complain
}
function yet_another_good_return ()
{
return (3 * 4) + (2 * 3); // should not complain
}
function yet_another_good_return_bis ()
{
return; // should not complain
}
function yet_another_good_return_3 ()
{
return ($a && $b); // should not complain
}
function bad_assignment ()
{
$a = "aaaaa"; // should not complain for this assignment block
$aa = 23;
$aaa = 1;
$b = "a";
$bb = 0;
$a = "aaaaa"; // should complain for this assignment block
$aa = 23;
$aaa = 1;
$b = "a";
$bb = 0;
$a = 1;
$axb[0] = 2; // should complain
$b = 2;
$a = 1; // should not complain
for ($i = 0;$i < 10;$i++) { // should not complain
$a = 1; // should not complain
}
}
function bad_foreach ()
{
foreach ($tests as &$test) { // should complain about missing unset
echo $test;
}
}
function another_bad_foreach ()
{
foreach ($tests as $yo => &$test) { // should complain about missing unset
echo $test;
}
}
function good_foreach ()
{ // should not complain
foreach ($tests as &$test) {
echo $test;
}
unset($test);
}
function another_good_foreach ()
{ // should not complain
foreach ($tests as $test) {
echo $test;
}
}
function good_indent ()
{
switch ($nothing) {
case 1:
something();
break; // should complain
case 2:
break; // should not complain
default:
break; // should complain
}
}
}
|