|
| 1 | +--- tests/wrong/file.php |
| 2 | ++++ PHP_CodeSniffer |
| 3 | +@@ -1,4 +1,5 @@ |
| 4 | + <?php |
| 5 | + |
| 6 | +-/* */ |
| 7 | +-return []; |
| 8 | +\ No newline at end of file |
| 9 | ++declare(strict_types=1); |
| 10 | ++ |
| 11 | ++return []; |
| 12 | +--- tests/wrong/Class1.php |
| 13 | ++++ PHP_CodeSniffer |
| 14 | +@@ -1,19 +1,17 @@ |
| 15 | + <?php |
| 16 | + |
| 17 | ++declare(strict_types=1); |
| 18 | + |
| 19 | + namespace Test; |
| 20 | + |
| 21 | +-use Something\Foo; |
| 22 | +- |
| 23 | +-use Something\bar; |
| 24 | +- |
| 25 | +-abstract final class Test { |
| 26 | +- |
| 27 | +- private $unused_field; |
| 28 | ++abstract final class Test |
| 29 | ++{ |
| 30 | ++ private $unused_field; |
| 31 | + |
| 32 | + const TEST = 'NOTOK'; |
| 33 | + |
| 34 | +- use MyTrait, MyTrait2; |
| 35 | ++ use MyTrait; |
| 36 | ++ use MyTrait2; |
| 37 | + |
| 38 | + public function __construct() |
| 39 | + { |
| 40 | +@@ -22,49 +20,51 @@ |
| 41 | + phpinfo2(); |
| 42 | + |
| 43 | + print_r([ |
| 44 | +- 1 |
| 45 | +- ]); |
| 46 | ++ 1, |
| 47 | ++ ]); |
| 48 | + |
| 49 | +- $this->test = new class() { |
| 50 | ++ $this->test = new class () { |
| 51 | + }; |
| 52 | + |
| 53 | + call_user_func(fn() => {}); |
| 54 | + } |
| 55 | + |
| 56 | +- private function unused() { |
| 57 | ++ private function unused() |
| 58 | ++ { |
| 59 | + $fooBar = 1; |
| 60 | +- $foo_bar = '1';; |
| 61 | ++ $foo_bar = '1'; |
| 62 | + |
| 63 | +- IF($foo_bar == '1') { |
| 64 | +- return true; |
| 65 | +- return true; |
| 66 | +- } |
| 67 | +- |
| 68 | +- $this->foo( |
| 69 | +- 'a', |
| 70 | +- 2 |
| 71 | ++ |
| 72 | ++ if ($foo_bar === '1') { |
| 73 | ++ return true; |
| 74 | ++ return true; |
| 75 | ++ } |
| 76 | ++ |
| 77 | ++ $this->foo( |
| 78 | ++ 'a', |
| 79 | ++ 2, |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | +- * @param string $a |
| 85 | + * @deprecated |
| 86 | + */ |
| 87 | +- private static function Foo(string $a, $b, $c) : array |object |
| 88 | ++ private static function Foo(string $a, $b, $c): array|object |
| 89 | + { |
| 90 | + return [$a, $b]; |
| 91 | + } |
| 92 | + |
| 93 | +- private function testUnion(null|float|int|string $a,): null|int|float |
| 94 | ++ private function testUnion(float|int|string|null $a,): int|float|null |
| 95 | + { |
| 96 | + return 1; |
| 97 | + } |
| 98 | + |
| 99 | +- private function testAssignmentInCondition(int $a): void { |
| 100 | +- if ($a == 1 && $b = 2) { |
| 101 | ++ private function testAssignmentInCondition(int $a): void |
| 102 | ++ { |
| 103 | ++ if ($a === 1 && $b = 2) { |
| 104 | + $c = 3; |
| 105 | + } |
| 106 | + |
| 107 | +- $c == 3 && $d = 4; |
| 108 | ++ $c === 3 && $d = 4; |
| 109 | + } |
| 110 | +-} |
| 111 | +\ No newline at end of file |
| 112 | ++} |
| 113 | +--- tests/wrong/ClassWrongAbstract.php |
| 114 | ++++ PHP_CodeSniffer |
| 115 | +@@ -2,54 +2,33 @@ |
| 116 | + |
| 117 | + declare(strict_types=1); |
| 118 | + |
| 119 | +- |
| 120 | + namespace wrong; |
| 121 | + |
| 122 | +-use RuntimeException; |
| 123 | +- |
| 124 | +-/** |
| 125 | +- * Class ClassWrongAbstract |
| 126 | +- */ |
| 127 | + abstract class ClassWrongAbstract |
| 128 | + { |
| 129 | +- |
| 130 | + abstract public function setOne(int $one = 1): void; |
| 131 | + |
| 132 | +- /** |
| 133 | +- * one getter. |
| 134 | +- * |
| 135 | +- * Created by me. |
| 136 | +- * User: me |
| 137 | +- * Date: now |
| 138 | +- * Time: now |
| 139 | +- * |
| 140 | +- */ |
| 141 | + public function getOne(): int |
| 142 | + { |
| 143 | +- //There should be a space separator |
| 144 | ++ // There should be a space separator |
| 145 | + return 1; |
| 146 | + } |
| 147 | + |
| 148 | +- #[Attribute1, Attribute2('var')] |
| 149 | +- #[Attribute3(), Attribute4] |
| 150 | + /** |
| 151 | + * Method comment |
| 152 | + */ |
| 153 | ++ #[Attribute1, Attribute2('var')] |
| 154 | ++ #[Attribute3(), Attribute4] |
| 155 | + public function method( |
| 156 | ++ /** @param int $parameter */ |
| 157 | + #[Attribute1] #[Attribute2] #[Attribute3] |
| 158 | + #[Attribute4] #[Attribute5] #[Attribute6] |
| 159 | +- /** @param int $parameter */ |
| 160 | + int $parameter, |
| 161 | + ): void { |
| 162 | +- /*There should be a space separator*/ |
| 163 | ++ /* There should be a space separator*/ |
| 164 | + echo $parameter; |
| 165 | +- # This comment is not allowed |
| 166 | +- #This is wrong, too |
| 167 | +- // |
| 168 | +- /**/ |
| 169 | +- |
| 170 | +- // |
| 171 | +- //The space is missing again |
| 172 | +- // |
| 173 | ++ // This comment is not allowed |
| 174 | ++ // This is wrong, too |
| 175 | ++ // The space is missing again |
| 176 | + } |
| 177 | + } |
| 178 | +--- tests/wrong/ContainsHTML.php |
| 179 | ++++ PHP_CodeSniffer |
| 180 | +@@ -3,18 +3,16 @@ |
| 181 | + declare(strict_types=1); |
| 182 | + |
| 183 | + $foo = [ |
| 184 | +- "foo" => 1, |
| 185 | ++ "foo" => 1, |
| 186 | + ]; |
| 187 | + |
| 188 | + $bar = [ |
| 189 | +- "bar" => 1, |
| 190 | ++ "bar" => 1, |
| 191 | + ]; |
| 192 | + |
| 193 | + eval("\$str = \"foo\";"); |
| 194 | + |
| 195 | +-// |
| 196 | +- |
| 197 | +-if (count($foo) == 1) { |
| 198 | ++if (count($foo) === 1) { |
| 199 | + } |
| 200 | + |
| 201 | + ?> |
| 202 | +--- tests/wrong/ClassMetrics.php |
| 203 | ++++ PHP_CodeSniffer |
| 204 | +@@ -1,8 +1,11 @@ |
| 205 | + <?php |
| 206 | + |
| 207 | ++declare(strict_types=1); |
| 208 | ++ |
| 209 | + namespace Test; |
| 210 | + |
| 211 | +-class ClassMetrics { |
| 212 | ++class ClassMetrics |
| 213 | ++{ |
| 214 | + public function foo($a, $b, $c, $d, $e, $f) |
| 215 | + { |
| 216 | + if ($a) { |
| 217 | +@@ -17,10 +20,6 @@ |
| 218 | + } |
| 219 | + } |
| 220 | + |
| 221 | +- if (true) { |
| 222 | +- return true; |
| 223 | +- } else { |
| 224 | +- return false; |
| 225 | +- } |
| 226 | ++ return true; |
| 227 | + } |
| 228 | + } |
| 229 | + |
0 commit comments