PHP Classes

File: vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.1.inc.fixed

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Download Installed Plugin   vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.1.inc.fixed   Download  
File: vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Tests/ControlStructures/ForLoopDeclarationUnitTest.1.inc.fixed
Role: Example script
Content type: text/plain
Description: Example script
Class: Download Installed Plugin
Download a WordPress plugin as a ZIP archive
Author: By
Last change:
Date: Yesterday
Size: 2,689 bytes
 

Contents

Class file image Download
<?php

// Valid.
for ($i = 0; $i < 10; $i++) {
}

// Invalid.
for ($i = 0; $i < 10; $i++) {
}

for (
$i = 0; $i < 10; $i++) {
}

for (
$i = 0; $i < 10; $i++) {
}

for (
$i = 0; $i < 10; $i++) {
}

// The works.
for ($i = 0; $i < 10; $i++) {
}

for (
$i = 0; $i < 10;) {
}

for (
$i = 0; $i < 10;) {
}

for (
$i = 0;; $i++) {
}
for (
$i = 0;; $i++) {
}

// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 1
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 1
for ( $i = 0; $i < 10; $i++ ) {}
for (
$i = 0; $i < 10; $i++ ) {}
for (
$i = 0; $i < 10; $i++ ) {}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

for (; $i < 10; $i++) {}
for (;
$i < 10; $i++) {}

// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 1
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 1
for ( ; $i < 10; $i++ ) {}
for ( ;
$i < 10; $i++ ) {}
for ( ;
$i < 10; $i++ ) {}

for (
$i = 0; $i < 10; ) {}
for (
$i = 0; $i < 10; ) {}
for (
$i = 0; $i < 10; ) {}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test handling of comments and inline annotations.
for (/*phpcs:enable*/ $i = 0 /*start*/; /*end*/$i < 10/*comment*/; $i++ /*comment*/) {}

// Test multi-line FOR control structure.
for ($i = 0; $i < 10; $i++) {}

// Test multi-line FOR control structure with comments and annotations.
for ($i = 0; /* Start */
   
$i < 10; /* phpcs:ignore Standard.Category.SniffName -- for reasons. */
   
$i++ // comment

) {}

// Test fixing each error in one go. Note: lines 78 + 82 contain trailing whitespace on purpose.
for ($i = 0; $i < 10; $i++) {}

// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 1
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 1
for ( $i = 0; $i < 10; $i++ ) {}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test with semicolon not belonging to for.
for ($i = function() { return $this->i ; }; $i < function() { return $this->max; }; $i++) {}
for (
$i = function() { return $this->i; }; $i < function() { return $this->max; }; $i++) {}

// phpcs:set Squiz.ControlStructures.ForLoopDeclaration ignoreNewlines true
for (
   
$i = 0;
   
$i < 5;
   
$i++
) {
   
// body here
}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration ignoreNewlines false