@@ -6,8 +6,7 @@ discard block |
||
| 6 | 6 | * https://github.com/johnkary/phpunit-speedtrap/ |
| 7 | 7 | * |
| 8 | 8 | */ |
| 9 | -class SpeedTrapListener implements PHPUnit_Framework_TestListener |
|
| 10 | -{ |
|
| 9 | +class SpeedTrapListener implements PHPUnit_Framework_TestListener { |
|
| 11 | 10 | /** |
| 12 | 11 | * Internal tracking for test suites. |
| 13 | 12 | * |
@@ -45,8 +44,7 @@ discard block |
||
| 45 | 44 | * |
| 46 | 45 | * @param array $options |
| 47 | 46 | */ |
| 48 | - public function __construct(array $options = array()) |
|
| 49 | - { |
|
| 47 | + public function __construct(array $options = array()) { |
|
| 50 | 48 | $this->loadOptions($options); |
| 51 | 49 | } |
| 52 | 50 | |
@@ -57,8 +55,7 @@ discard block |
||
| 57 | 55 | * @param Exception $e |
| 58 | 56 | * @param float $time |
| 59 | 57 | */ |
| 60 | - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 61 | - { |
|
| 58 | + public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { |
|
| 62 | 59 | } |
| 63 | 60 | |
| 64 | 61 | /** |
@@ -69,8 +66,7 @@ discard block |
||
| 69 | 66 | * @param float $time |
| 70 | 67 | * @since Method available since Release 5.1.0 |
| 71 | 68 | */ |
| 72 | - public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) |
|
| 73 | - { |
|
| 69 | + public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time) { |
|
| 74 | 70 | } |
| 75 | 71 | |
| 76 | 72 | /** |
@@ -80,8 +76,7 @@ discard block |
||
| 80 | 76 | * @param PHPUnit_Framework_AssertionFailedError $e |
| 81 | 77 | * @param float $time |
| 82 | 78 | */ |
| 83 | - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) |
|
| 84 | - { |
|
| 79 | + public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { |
|
| 85 | 80 | } |
| 86 | 81 | |
| 87 | 82 | /** |
@@ -91,8 +86,7 @@ discard block |
||
| 91 | 86 | * @param Exception $e |
| 92 | 87 | * @param float $time |
| 93 | 88 | */ |
| 94 | - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 95 | - { |
|
| 89 | + public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { |
|
| 96 | 90 | } |
| 97 | 91 | |
| 98 | 92 | /** |
@@ -103,8 +97,7 @@ discard block |
||
| 103 | 97 | * @param float $time |
| 104 | 98 | * @since Method available since Release 4.0.0 |
| 105 | 99 | */ |
| 106 | - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 107 | - { |
|
| 100 | + public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) { |
|
| 108 | 101 | } |
| 109 | 102 | |
| 110 | 103 | /** |
@@ -114,8 +107,7 @@ discard block |
||
| 114 | 107 | * @param Exception $e |
| 115 | 108 | * @param float $time |
| 116 | 109 | */ |
| 117 | - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) |
|
| 118 | - { |
|
| 110 | + public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { |
|
| 119 | 111 | } |
| 120 | 112 | |
| 121 | 113 | /** |
@@ -123,8 +115,7 @@ discard block |
||
| 123 | 115 | * |
| 124 | 116 | * @param PHPUnit_Framework_Test $test |
| 125 | 117 | */ |
| 126 | - public function startTest(PHPUnit_Framework_Test $test) |
|
| 127 | - { |
|
| 118 | + public function startTest(PHPUnit_Framework_Test $test) { |
|
| 128 | 119 | } |
| 129 | 120 | |
| 130 | 121 | /** |
@@ -133,9 +124,10 @@ discard block |
||
| 133 | 124 | * @param PHPUnit_Framework_Test $test |
| 134 | 125 | * @param float $time |
| 135 | 126 | */ |
| 136 | - public function endTest(PHPUnit_Framework_Test $test, $time) |
|
| 137 | - { |
|
| 138 | - if (!$test instanceof PHPUnit_Framework_TestCase) return; |
|
| 127 | + public function endTest(PHPUnit_Framework_Test $test, $time) { |
|
| 128 | + if (!$test instanceof PHPUnit_Framework_TestCase) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 139 | 131 | |
| 140 | 132 | $time = $this->toMilliseconds($time); |
| 141 | 133 | $threshold = $this->getSlowThreshold($test); |
@@ -150,8 +142,7 @@ discard block |
||
| 150 | 142 | * |
| 151 | 143 | * @param PHPUnit_Framework_TestSuite $suite |
| 152 | 144 | */ |
| 153 | - public function startTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 154 | - { |
|
| 145 | + public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { |
|
| 155 | 146 | $this->suites++; |
| 156 | 147 | } |
| 157 | 148 | |
@@ -160,8 +151,7 @@ discard block |
||
| 160 | 151 | * |
| 161 | 152 | * @param PHPUnit_Framework_TestSuite $suite |
| 162 | 153 | */ |
| 163 | - public function endTestSuite(PHPUnit_Framework_TestSuite $suite) |
|
| 164 | - { |
|
| 154 | + public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { |
|
| 165 | 155 | $this->suites--; |
| 166 | 156 | |
| 167 | 157 | if (0 === $this->suites && $this->hasSlowTests()) { |
@@ -180,8 +170,7 @@ discard block |
||
| 180 | 170 | * @param int $slowThreshold Test execution time at which a test should be considered slow (milliseconds) |
| 181 | 171 | * @return bool |
| 182 | 172 | */ |
| 183 | - protected function isSlow($time, $slowThreshold) |
|
| 184 | - { |
|
| 173 | + protected function isSlow($time, $slowThreshold) { |
|
| 185 | 174 | return $time >= $slowThreshold; |
| 186 | 175 | } |
| 187 | 176 | |
@@ -191,8 +180,7 @@ discard block |
||
| 191 | 180 | * @param PHPUnit_Framework_TestCase $test |
| 192 | 181 | * @param int $time Test execution time in milliseconds |
| 193 | 182 | */ |
| 194 | - protected function addSlowTest(PHPUnit_Framework_TestCase $test, $time) |
|
| 195 | - { |
|
| 183 | + protected function addSlowTest(PHPUnit_Framework_TestCase $test, $time) { |
|
| 196 | 184 | $label = $this->makeLabel($test); |
| 197 | 185 | |
| 198 | 186 | $this->slow[$label] = $time; |
@@ -203,8 +191,7 @@ discard block |
||
| 203 | 191 | * |
| 204 | 192 | * @return bool |
| 205 | 193 | */ |
| 206 | - protected function hasSlowTests() |
|
| 207 | - { |
|
| 194 | + protected function hasSlowTests() { |
|
| 208 | 195 | return !empty($this->slow); |
| 209 | 196 | } |
| 210 | 197 | |
@@ -214,8 +201,7 @@ discard block |
||
| 214 | 201 | * @param float $time |
| 215 | 202 | * @return int |
| 216 | 203 | */ |
| 217 | - protected function toMilliseconds($time) |
|
| 218 | - { |
|
| 204 | + protected function toMilliseconds($time) { |
|
| 219 | 205 | return (int) round($time * 1000); |
| 220 | 206 | } |
| 221 | 207 | |
@@ -225,8 +211,7 @@ discard block |
||
| 225 | 211 | * @param PHPUnit_Framework_TestCase $test |
| 226 | 212 | * @return string |
| 227 | 213 | */ |
| 228 | - protected function makeLabel(PHPUnit_Framework_TestCase $test) |
|
| 229 | - { |
|
| 214 | + protected function makeLabel(PHPUnit_Framework_TestCase $test) { |
|
| 230 | 215 | return sprintf('%s:%s', get_class($test), $test->getName()); |
| 231 | 216 | } |
| 232 | 217 | |
@@ -235,8 +220,7 @@ discard block |
||
| 235 | 220 | * |
| 236 | 221 | * @return int |
| 237 | 222 | */ |
| 238 | - protected function getReportLength() |
|
| 239 | - { |
|
| 223 | + protected function getReportLength() { |
|
| 240 | 224 | return min(count($this->slow), $this->reportLength); |
| 241 | 225 | } |
| 242 | 226 | |
@@ -245,8 +229,7 @@ discard block |
||
| 245 | 229 | * |
| 246 | 230 | * @return int Number of hidden slow tests |
| 247 | 231 | */ |
| 248 | - protected function getHiddenCount() |
|
| 249 | - { |
|
| 232 | + protected function getHiddenCount() { |
|
| 250 | 233 | $total = count($this->slow); |
| 251 | 234 | $showing = $this->getReportLength($this->slow); |
| 252 | 235 | |
@@ -261,16 +244,14 @@ discard block |
||
| 261 | 244 | /** |
| 262 | 245 | * Renders slow test report header. |
| 263 | 246 | */ |
| 264 | - protected function renderHeader() |
|
| 265 | - { |
|
| 247 | + protected function renderHeader() { |
|
| 266 | 248 | echo sprintf("\n\nYou should really fix these slow tests (>%sms)...\n", $this->slowThreshold); |
| 267 | 249 | } |
| 268 | 250 | |
| 269 | 251 | /** |
| 270 | 252 | * Renders slow test report body. |
| 271 | 253 | */ |
| 272 | - protected function renderBody() |
|
| 273 | - { |
|
| 254 | + protected function renderBody() { |
|
| 274 | 255 | $slowTests = $this->slow; |
| 275 | 256 | |
| 276 | 257 | $length = $this->getReportLength($slowTests); |
@@ -285,8 +266,7 @@ discard block |
||
| 285 | 266 | /** |
| 286 | 267 | * Renders slow test report footer. |
| 287 | 268 | */ |
| 288 | - protected function renderFooter() |
|
| 289 | - { |
|
| 269 | + protected function renderFooter() { |
|
| 290 | 270 | if ($hidden = $this->getHiddenCount($this->slow)) { |
| 291 | 271 | echo sprintf("...and there %s %s more above your threshold hidden from view", $hidden == 1 ? 'is' : 'are', $hidden); |
| 292 | 272 | } |
@@ -297,8 +277,7 @@ discard block |
||
| 297 | 277 | * |
| 298 | 278 | * @param array $options |
| 299 | 279 | */ |
| 300 | - protected function loadOptions(array $options) |
|
| 301 | - { |
|
| 280 | + protected function loadOptions(array $options) { |
|
| 302 | 281 | $this->slowThreshold = isset($options['slowThreshold']) ? $options['slowThreshold'] : 500; |
| 303 | 282 | $this->reportLength = isset($options['reportLength']) ? $options['reportLength'] : 10; |
| 304 | 283 | } |
@@ -319,8 +298,7 @@ discard block |
||
| 319 | 298 | * @param PHPUnit_Framework_TestCase $test |
| 320 | 299 | * @return int |
| 321 | 300 | */ |
| 322 | - protected function getSlowThreshold(PHPUnit_Framework_TestCase $test) |
|
| 323 | - { |
|
| 301 | + protected function getSlowThreshold(PHPUnit_Framework_TestCase $test) { |
|
| 324 | 302 | $ann = $test->getAnnotations(); |
| 325 | 303 | |
| 326 | 304 | return isset($ann['method']['slowThreshold'][0]) ? $ann['method']['slowThreshold'][0] : $this->slowThreshold; |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | $_tests_dir = getenv('WP_TESTS_DIR'); |
| 4 | -if ( !$_tests_dir ) $_tests_dir = '/tmp/wordpress-tests-lib'; |
|
| 4 | +if ( !$_tests_dir ) { |
|
| 5 | + $_tests_dir = '/tmp/wordpress-tests-lib'; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | require_once $_tests_dir . '/includes/functions.php'; |
| 7 | 9 | |
@@ -10,8 +10,10 @@ |
||
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | // These should all trigger an error. |
| 13 | -if ( ereg( '[A-Za-z]+', $title, $regs ) ) // Bad, ereg deprecated. Use preg_match instead. |
|
| 13 | +if ( ereg( '[A-Za-z]+', $title, $regs ) ) { |
|
| 14 | + // Bad, ereg deprecated. Use preg_match instead. |
|
| 14 | 15 | die( $regs ); |
| 16 | +} |
|
| 15 | 17 | |
| 16 | 18 | if ( eregi( '[a-z]+', $title, $regs ) ) {} // Bad, eregi deprecated. Use preg_match instead. |
| 17 | 19 | |
@@ -1,73 +1,95 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( $true == true || $false == false ) { // Bad x 2 (in an 'if'). |
|
| 2 | +if ( $true == true || $false == false ) { |
|
| 3 | +// Bad x 2 (in an 'if'). |
|
| 3 | 4 | echo 'True'; |
| 4 | -} elseif ( $true == true && $false == true ) { // Bad x 2 (in an 'elseif'). |
|
| 5 | +} elseif ( $true == true && $false == true ) { |
|
| 6 | +// Bad x 2 (in an 'elseif'). |
|
| 5 | 7 | echo 'False'; |
| 6 | -} elseif ( false == $true && true == $false ) { // Good - this is the correct way to do conditional checks. |
|
| 8 | +} elseif ( false == $true && true == $false ) { |
|
| 9 | +// Good - this is the correct way to do conditional checks. |
|
| 7 | 10 | echo 'False'; |
| 8 | 11 | } |
| 9 | 12 | |
| 10 | 13 | // Test for 'equals' conditional. |
| 11 | -if ( $true == true ) { // Bad x 1. |
|
| 14 | +if ( $true == true ) { |
|
| 15 | +// Bad x 1. |
|
| 12 | 16 | echo 'True'; |
| 13 | -} elseif ( false == $true ) { // Good. |
|
| 17 | +} elseif ( false == $true ) { |
|
| 18 | +// Good. |
|
| 14 | 19 | echo 'False'; |
| 15 | 20 | } |
| 16 | 21 | |
| 17 | 22 | // Test for 'not equals' conditional. |
| 18 | -if ( $true != true ) { // Bad x 1. |
|
| 23 | +if ( $true != true ) { |
|
| 24 | +// Bad x 1. |
|
| 19 | 25 | echo 'True'; |
| 20 | -} elseif ( false != $true ) { // Good. |
|
| 26 | +} elseif ( false != $true ) { |
|
| 27 | +// Good. |
|
| 21 | 28 | echo 'False'; |
| 22 | 29 | } |
| 23 | 30 | |
| 24 | 31 | // Test for 'exactly equals' conditional. |
| 25 | -if ( $true === true ) { // Bad x 1. |
|
| 32 | +if ( $true === true ) { |
|
| 33 | +// Bad x 1. |
|
| 26 | 34 | echo 'True'; |
| 27 | -} elseif ( false === $true ) { // Good. |
|
| 35 | +} elseif ( false === $true ) { |
|
| 36 | +// Good. |
|
| 28 | 37 | echo 'False'; |
| 29 | 38 | } |
| 30 | 39 | |
| 31 | 40 | // Test for 'not exactly equals' conditional. |
| 32 | -if ( $true !== true ) { // Bad x 1. |
|
| 41 | +if ( $true !== true ) { |
|
| 42 | +// Bad x 1. |
|
| 33 | 43 | echo 'True'; |
| 34 | -} elseif ( false !== $true ) { // Good. |
|
| 44 | +} elseif ( false !== $true ) { |
|
| 45 | +// Good. |
|
| 35 | 46 | echo 'False'; |
| 36 | 47 | } |
| 37 | 48 | |
| 38 | 49 | // Make sure the test excludes functions on the conditional check. |
| 39 | -if ( strtolower( $check ) == $true ) { // Good. |
|
| 50 | +if ( strtolower( $check ) == $true ) { |
|
| 51 | +// Good. |
|
| 40 | 52 | echo 'True'; |
| 41 | 53 | } |
| 42 | 54 | // Makes sure the test excludes variable casting in the conditional check. |
| 43 | -if ( true == (bool) $true ) { // Good. |
|
| 55 | +if ( true == (bool) $true ) { |
|
| 56 | +// Good. |
|
| 44 | 57 | echo 'True'; |
| 45 | -} elseif ( false == $true ) { // Good. |
|
| 58 | +} elseif ( false == $true ) { |
|
| 59 | +// Good. |
|
| 46 | 60 | echo 'False'; |
| 47 | 61 | } |
| 48 | 62 | // Testing for string comparison. |
| 49 | -if ( $true == 'true' ) { // Bad x 1. |
|
| 63 | +if ( $true == 'true' ) { |
|
| 64 | +// Bad x 1. |
|
| 50 | 65 | echo 'True'; |
| 51 | -} elseif ( 'false' == $true ) { // Good x 1. |
|
| 66 | +} elseif ( 'false' == $true ) { |
|
| 67 | +// Good x 1. |
|
| 52 | 68 | echo 'False'; |
| 53 | 69 | } |
| 54 | 70 | // Testing for integer comparison. |
| 55 | -if ( $true == 0 ) { // Bad x 1. |
|
| 71 | +if ( $true == 0 ) { |
|
| 72 | +// Bad x 1. |
|
| 56 | 73 | echo 'True'; |
| 57 | -} elseif ( 1 == $false ) { // Good x 1. |
|
| 74 | +} elseif ( 1 == $false ) { |
|
| 75 | +// Good x 1. |
|
| 58 | 76 | echo 'False'; |
| 59 | 77 | } |
| 60 | 78 | |
| 61 | 79 | // Testing constant comparison. |
| 62 | -if ( $taxonomy === MyClass::TAXONOMY_SLUG ) { // Bad. |
|
| 80 | +if ( $taxonomy === MyClass::TAXONOMY_SLUG ) { |
|
| 81 | +// Bad. |
|
| 63 | 82 | $link = true; |
| 64 | -} elseif ( MyClass::TAXONOMY_SLUG === $taxonomy ) { // Ok. |
|
| 83 | +} elseif ( MyClass::TAXONOMY_SLUG === $taxonomy ) { |
|
| 84 | +// Ok. |
|
| 65 | 85 | $link = false; |
| 66 | 86 | } |
| 67 | 87 | |
| 68 | -if ( $foo === FOO_CONSTANT ) { // Bad. |
|
| 88 | +if ( $foo === FOO_CONSTANT ) { |
|
| 89 | +// Bad. |
|
| 69 | 90 | $link = true; |
| 70 | -} elseif ( FOO_CONSTANT === $foo ) { // Ok. |
|
| 91 | +} elseif ( FOO_CONSTANT === $foo ) { |
|
| 92 | +// Ok. |
|
| 71 | 93 | $link = false; |
| 72 | 94 | } |
| 73 | 95 | |
@@ -75,7 +97,8 @@ discard block |
||
| 75 | 97 | |
| 76 | 98 | $accessibility_mode = ( 'on' === sanitize_key( $_GET['accessibility-mode'] ) ) ? 'on' : 'off'; // Ok. |
| 77 | 99 | |
| 78 | -if ( $on !== self::$network_mode ) { // Ok. |
|
| 100 | +if ( $on !== self::$network_mode ) { |
|
| 101 | +// Ok. |
|
| 79 | 102 | self::$network_mode = (bool) $on; |
| 80 | 103 | } |
| 81 | 104 | |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | register_globals(); // Bad. |
| 46 | 46 | |
| 47 | 47 | query_posts( 'post_type=attachment' ); // Bad, use WP_Query instead. |
| 48 | -while ( have_posts() ){ |
|
| 48 | +while ( have_posts() ) { |
|
| 49 | 49 | the_post(); |
| 50 | 50 | // ... |
| 51 | 51 | } |
@@ -1,21 +1,27 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | // Test for 'equals' conditionals. |
| 3 | -if ( true == $true ) { // Bad. |
|
| 3 | +if ( true == $true ) { |
|
| 4 | +// Bad. |
|
| 4 | 5 | echo 'True'; |
| 5 | -} elseif ( false === $true ) { // Ok. |
|
| 6 | +} elseif ( false === $true ) { |
|
| 7 | +// Ok. |
|
| 6 | 8 | echo 'False'; |
| 7 | 9 | } |
| 8 | 10 | |
| 9 | 11 | // Test for 'not equals' conditionals. |
| 10 | -if ( true != $true ) { // Bad. |
|
| 12 | +if ( true != $true ) { |
|
| 13 | +// Bad. |
|
| 11 | 14 | echo 'True'; |
| 12 | -} elseif ( true <> $true ) { // Bad. |
|
| 15 | +} elseif ( true <> $true ) { |
|
| 16 | +// Bad. |
|
| 13 | 17 | echo 'False'; |
| 14 | -} elseif ( false !== $true ) { // Ok. |
|
| 18 | +} elseif ( false !== $true ) { |
|
| 19 | +// Ok. |
|
| 15 | 20 | echo 'False'; |
| 16 | 21 | } |
| 17 | 22 | |
| 18 | 23 | // Test for whitelisting. |
| 19 | -if ( true == $true ) { // Loose comparison, OK. |
|
| 24 | +if ( true == $true ) { |
|
| 25 | +// Loose comparison, OK. |
|
| 20 | 26 | echo 'True'; |
| 21 | 27 | } |
| 22 | 28 | \ No newline at end of file |
@@ -26,7 +26,8 @@ |
||
| 26 | 26 | 'orderby' => 'title', // Good. |
| 27 | 27 | ), |
| 28 | 28 | array( |
| 29 | - 'closure' => function () { // Good, closures allowed. |
|
| 29 | + 'closure' => function () { |
|
| 30 | +// Good, closures allowed. |
|
| 30 | 31 | return array(); |
| 31 | 32 | }, |
| 32 | 33 | ), |
@@ -6,7 +6,8 @@ discard block |
||
| 6 | 6 | |
| 7 | 7 | foo( $_POST['whitelisted_with_prefix'] ); // WPCS: input var okay. |
| 8 | 8 | |
| 9 | -if ( $_GET['test'] && foo() && $bar ) { // input var okay |
|
| 9 | +if ( $_GET['test'] && foo() && $bar ) { |
|
| 10 | +// input var okay |
|
| 10 | 11 | taz(); |
| 11 | 12 | } |
| 12 | 13 | |
@@ -17,4 +18,5 @@ discard block |
||
| 17 | 18 | $_REQUEST['wp_customize'] = 'on'; // Ok. |
| 18 | 19 | |
| 19 | 20 | // Issue: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/542 |
| 20 | -if ( isset( $_GET['updated'] ) ) { // input var okay ?> |
|
| 21 | +if ( isset( $_GET['updated'] ) ) { |
|
| 22 | +// input var okay ?> |
|
@@ -10,7 +10,8 @@ |
||
| 10 | 10 | |
| 11 | 11 | $query = "SELECT * FROM $wpdb->posts"; // Ok. |
| 12 | 12 | |
| 13 | -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Bad. |
|
| 13 | +if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
| 14 | +// Bad. |
|
| 14 | 15 | foo( $_SERVER['HTTP_USER_AGENT'] ); // Bad. |
| 15 | 16 | } |
| 16 | 17 | |