blank-linesfixable
Enforce consistent linebreak spaces
Examples
- Examples of correct code for this rule using default options
Classes, interfaces, traits, enums, methods, properties, constants
php
<?php
/**
* Test Class
*/
class Test {
/**
* @var int $a A
*/
private $a;
/**
* @var int $b B
*/
private $b;
/**
* Test constructor.
*/
public function __construct() {
// Inner comment
$this->a = 1;
$this->b = 2;
}
/**
* Test
*/
public function test() {
/*
* Block comment
*/
// Another comment
$this->a = 1;
$this->b = 2;
// Trailing comment
}
}
/**
* Common Utilities
*/
trait Common {
/**
* Test constructor.
*/
public function log($data) {
// Inner comment
if($data) {
// Inner comment
echo "DATA";
}
}
}
/**
* Test Interface
*/
interface TestInterface {
/**
* Test constructor.
*/
public function log($data);
}
/**
* Status
*/
enum Status {
/**
* Draft
*/
case DRAFT;
case PUBLISHED;
case ARCHIVED;
/**
* Color
*/
public function color(): string {
return match($this) {
Status::DRAFT => 'grey',
Status::PUBLISHED => 'green',
Status::ARCHIVED => 'red',
};
}
}
Control structures, functions
php
<?php
for ($i; $i < 10; $i++) :
/* taqwim-disable-next-line */
for($j; $j < 10; $j++) {
// Test
echo "Index: $i, Second Index: $j";
}
endfor;
/**
* Switch statement
*/
switch ($i) {
// Case 1
case 1:
// inner comment
foreach($items as $item) {
// inner comment
echo $item;
}
echo "1";
// Another foreach
foreach($items as $item) :
// inner comment
echo $item;
endforeach;
break;
// Case 2
case 2:
// inner comment
if($i == 2) {
// inner comment
echo "2";
}
break;
// Default case
default:
for($j; $j < 10; $j++) {
// Test
echo "Index: $i, Second Index: $j";
}
break;
}
/**
* Docblock comment
*/
function foo() {
/* Comment block */
$a = 1;
$b = 2;
$c = 3;
}
function test(){
echo "Hello";
// Line comment
echo "World";
}
Try/catch and if/else statements
php
<?php
try {
$a = 1;
$b = 2;
$c = 3;
} catch (Exception $e) {
// Test
echo "Index: $i, Second Index: $j";
} catch (Exception $e) {
// Test
echo "Index: $i, Second Index: $j";
} finally {
// Test
echo "Index: $i, Second Index: $j";
}
if ($a) {
// Test
echo "Index: $i, Second Index: $j";
} elseif ($b) {
// Test
echo "Index: $i, Second Index: $j";
} else {
// Test
echo "Index: $i, Second Index: $j";
}
// Block padding is not applied to if/elseif/else statements
// due to parser limitations
if($a):
// Test
echo "Index: $i, Second Index: $j";
elseif($b) :
// Test
echo "First elseif condition";
elseif($b) :
// Test
echo "Second elseif condition";
else :
// Test
echo "Index: $i, Second Index: $j";
endif;
- Examples of incorrect code for this rule using default options
Classes, interfaces, traits, enums, methods, properties, constants
php
<?php
/**
* Test Class
*/
class Test {
/**
* @var int $a A
*/
private $a;
/**
* @var int $b B
*/
private $b;
/**
* Test constructor.
*/
public function __construct() {
// Inner comment
$this->a = 1;
$this->b = 2;
}
/**
* Test
*/
public function test() {
/*
* Block comment
*/
// Another comment
$this->a = 1;
$this->b = 2;
// Trailing comment
}
}
/**
* Common Utilities
*/
trait Common {
/**
* Test constructor.
*/
public function log($data) {
// Inner comment
if($data) {
// Inner comment
echo "DATA";
}
}
}
/**
* Test Interface
*/
interface TestInterface {
/**
* Test constructor.
*/
public function log($data);
}
/**
* Status
*/
enum Status {
/**
* Draft
*/
case DRAFT;
case PUBLISHED;
case ARCHIVED;
/**
* Color
*/
public function color(): string {
return match($this) {
Status::DRAFT => 'grey',
Status::PUBLISHED => 'green',
Status::ARCHIVED => 'red',
};
}
}
Control structures, functions
php
<?php
for ($i; $i < 10; $i++) :
/* taqwim-disable-next-line */
for($j; $j < 10; $j++) {
// Test
echo "Index: $i, Second Index: $j";
}
endfor;
/**
* Switch statement
*/
switch ($i) {
// Case 1
case 1:
// inner comment
foreach($items as $item) {
// inner comment
echo $item;
}
echo "1";
// Another foreach
foreach($items as $item) {
// inner comment
echo $item;
}
break;
// Case 2
case 2:
// inner comment
if($i == 2) {
// inner comment
echo "2";
}
break;
// Default case
default:
for($j; $j < 10; $j++) {
// Test
echo "Index: $i, Second Index: $j";
}
break;
}
/**
* Docblock comment
*/
function foo() {
/* Comment block */
$a = 1;
$b = 2;
$c = 3;
}
function test(){
echo "Hello";
// Line comment
echo "World";
}
Try/catch and if/else statements
php
<?php
try {
// Comment with top padding inside try block
$a = 1;
$b = 2;
$c = 3;
} catch (Exception $e) {
// Test
echo "Index: $i, Second Index: $j";
} catch (Exception $e) {
echo "Index: $i, Second Index: $j";
} finally {
// Test
echo "Index: $i, Second Index: $j";
}
if ($a) {
// Test
echo "Index: $i, Second Index: $j";
} elseif ($b) {
// Test
echo "Index: $i, Second Index: $j";
} else {
echo "Index: $i, Second Index: $j";
}
// Block padding is not applied to if/elseif/else statements
// due to parser limitations
if($a):
// Test
echo "Index: $i, Second Index: $j";
elseif($b) :
// Test
echo "Index: $i, Second Index: $j";
else :
// Test
echo "Index: $i, Second Index: $j";
endif;