Fork me on GitHub
a Sensio Labs Product

Remote Void (v2.18.5) edition

Rule blank_line_before_statement

An empty line feed must precede any configured statement.

Configuration

statements

List of statements which must be preceded by an empty line.

Allowed values: a subset of ['break', 'case', 'continue', 'declare', 'default', 'die', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']

Default value: ['break', 'continue', 'declare', 'return', 'throw', 'try']

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
 function A() {
     echo 1;
+
     return 1;
 }

Example #2

With configuration: ['statements' => ['break']].

--- Original
+++ New
 <?php
 switch ($foo) {
     case 42:
         $bar->process();
+
         break;
     case 44:
         break;
 }

Example #3

With configuration: ['statements' => ['continue']].

--- Original
+++ New
 <?php
 foreach ($foo as $bar) {
     if ($bar->isTired()) {
         $bar->sleep();
+
         continue;
     }
 }

Example #4

With configuration: ['statements' => ['do']].

--- Original
+++ New
 <?php
 $i = 0;
+
 do {
     echo $i;
 } while ($i > 0);

Example #5

With configuration: ['statements' => ['exit']].

--- Original
+++ New
 <?php
 if ($foo === false) {
     exit(0);
 } else {
     $bar = 9000;
+
     exit(1);
 }

Example #6

With configuration: ['statements' => ['goto']].

--- Original
+++ New
 <?php
 a:

 if ($foo === false) {
     goto a;
 } else {
     $bar = 9000;
+
     goto b;
 }

Example #7

With configuration: ['statements' => ['if']].

--- Original
+++ New
 <?php
 $a = 9000;
+
 if (true) {
     $foo = $bar;
 }

Example #8

With configuration: ['statements' => ['return']].

--- Original
+++ New
 <?php

 if (true) {
     $foo = $bar;
+
     return;
 }

Example #9

With configuration: ['statements' => ['switch']].

--- Original
+++ New
 <?php
 $a = 9000;
+
 switch ($a) {
     case 42:
         break;
 }

Example #10

With configuration: ['statements' => ['throw']].

--- Original
+++ New
 <?php
 if (null === $a) {
     $foo->bar();
+
     throw new \UnexpectedValueException("A cannot be null.");
 }

Example #11

With configuration: ['statements' => ['try']].

--- Original
+++ New
 <?php
 $a = 9000;
+
 try {
     $foo->bar();
 } catch (\Exception $exception) {
     $a = -1;
 }

Example #12

With configuration: ['statements' => ['yield']].

--- Original
+++ New
 <?php

 if (true) {
     $foo = $bar;
+
     yield $foo;
 }

Rule sets

The rule is part of the following rule sets:

@PhpCsFixer

Using the @PhpCsFixer rule set will enable the blank_line_before_statement rule with the config below:

['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try']]

@Symfony

Using the @Symfony rule set will enable the blank_line_before_statement rule with the config below:

['statements' => ['return']]

The logo is © 2010-2014 Sensio Labs