123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- ====================================
- 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', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', 'yield_from']``
- Default value: ``['break', 'continue', 'declare', 'return', 'throw', 'try']``
- Examples
- --------
- Example #1
- ~~~~~~~~~~
- *Default* configuration.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- function A() {
- echo 1;
- +
- return 1;
- }
- Example #2
- ~~~~~~~~~~
- With configuration: ``['statements' => ['break']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- switch ($foo) {
- case 42:
- $bar->process();
- +
- break;
- case 44:
- break;
- }
- Example #3
- ~~~~~~~~~~
- With configuration: ``['statements' => ['continue']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- foreach ($foo as $bar) {
- if ($bar->isTired()) {
- $bar->sleep();
- +
- continue;
- }
- }
- Example #4
- ~~~~~~~~~~
- With configuration: ``['statements' => ['do']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- $i = 0;
- +
- do {
- echo $i;
- } while ($i > 0);
- Example #5
- ~~~~~~~~~~
- With configuration: ``['statements' => ['exit']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- if ($foo === false) {
- exit(0);
- } else {
- $bar = 9000;
- +
- exit(1);
- }
- Example #6
- ~~~~~~~~~~
- With configuration: ``['statements' => ['goto']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- a:
- if ($foo === false) {
- goto a;
- } else {
- $bar = 9000;
- +
- goto b;
- }
- Example #7
- ~~~~~~~~~~
- With configuration: ``['statements' => ['if']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- $a = 9000;
- +
- if (true) {
- $foo = $bar;
- }
- Example #8
- ~~~~~~~~~~
- With configuration: ``['statements' => ['return']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- if (true) {
- $foo = $bar;
- +
- return;
- }
- Example #9
- ~~~~~~~~~~
- With configuration: ``['statements' => ['switch']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- $a = 9000;
- +
- switch ($a) {
- case 42:
- break;
- }
- Example #10
- ~~~~~~~~~~~
- With configuration: ``['statements' => ['throw']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- if (null === $a) {
- $foo->bar();
- +
- throw new \UnexpectedValueException("A cannot be null.");
- }
- Example #11
- ~~~~~~~~~~~
- With configuration: ``['statements' => ['try']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- $a = 9000;
- +
- try {
- $foo->bar();
- } catch (\Exception $exception) {
- $a = -1;
- }
- Example #12
- ~~~~~~~~~~~
- With configuration: ``['statements' => ['yield']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- function getValues() {
- yield 1;
- +
- yield 2;
- +
- // comment
- yield 3;
- }
- Rule sets
- ---------
- The rule is part of the following rule sets:
- - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
- ``['statements' => ['break', 'case', 'continue', 'declare', 'default', 'exit', 'goto', 'include', 'include_once', 'phpdoc', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'yield', 'yield_from']]``
- - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
- ``['statements' => ['return']]``
- References
- ----------
- - Fixer class: `PhpCsFixer\\Fixer\\Whitespace\\BlankLineBeforeStatementFixer <./../../../src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php>`_
- - Test class: `PhpCsFixer\\Tests\\Fixer\\Whitespace\\BlankLineBeforeStatementFixerTest <./../../../tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php>`_
- The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
|