2018-04-17 23:58:51 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Ely\CS\Test\Fixer\Whitespace;
|
|
|
|
|
|
|
|
use Ely\CS\Fixer\Whitespace\LineBreakAfterStatementsFixer;
|
2022-09-20 05:07:57 +05:30
|
|
|
use PhpCsFixer\AbstractFixer;
|
2018-04-17 23:58:51 +05:30
|
|
|
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Ely\CS\Fixer\Whitespace\LineBreakAfterStatementsFixer
|
|
|
|
*
|
|
|
|
* @author ErickSkrauch <erickskrauch@ely.by>
|
|
|
|
*/
|
|
|
|
class LineBreakAfterStatementsFixerTest extends AbstractFixerTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideFixCases
|
|
|
|
*/
|
2022-09-20 05:07:57 +05:30
|
|
|
public function testFix(string $expected, ?string $input = null): void {
|
2018-04-17 23:58:51 +05:30
|
|
|
$this->doTest($expected, $input);
|
|
|
|
}
|
|
|
|
|
2022-09-20 05:07:57 +05:30
|
|
|
public function provideFixCases(): iterable {
|
2018-04-17 23:58:51 +05:30
|
|
|
// Simple cases
|
2022-09-20 05:07:57 +05:30
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} else {
|
|
|
|
// another code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} else {
|
|
|
|
// another code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
for ($i = 0; $i < 3; $i++) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
for ($i = 0; $i < 3; $i++) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
while ($i < 10) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
while ($i < 10) {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
// code
|
|
|
|
} while ($i < 10);
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
// code
|
|
|
|
} while ($i < 10);
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
switch ("str") {
|
|
|
|
case "a":
|
|
|
|
break;
|
|
|
|
case "b":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
switch ("str") {
|
|
|
|
case "a":
|
|
|
|
break;
|
|
|
|
case "b":
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
2018-04-17 23:58:51 +05:30
|
|
|
// Extended cases
|
2022-09-20 05:07:57 +05:30
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} else if ("a" === "c") {
|
|
|
|
// code
|
|
|
|
} else if ("a" === "d") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} else if ("a" === "c") {
|
|
|
|
// code
|
|
|
|
} else if ("a" === "d") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} elseif ("a" === "c") {
|
|
|
|
// code
|
|
|
|
} elseif ("a" === "d") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b") {
|
|
|
|
// code
|
|
|
|
} elseif ("a" === "c") {
|
|
|
|
// code
|
|
|
|
} elseif ("a" === "d") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str) {
|
|
|
|
if ($str === "foo") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str) {
|
|
|
|
if ($str === "foo") {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
switch ("str") {
|
|
|
|
case "a": {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "b": {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
switch ("str") {
|
|
|
|
case "a": {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "b": {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-04-17 23:58:51 +05:30
|
|
|
'<?php
|
|
|
|
$a = "prev statement";
|
|
|
|
foreach ($coordinates as $coordinate) {
|
2018-08-07 14:55:47 +05:30
|
|
|
$points = explode(",", $coordinate);
|
2018-04-17 23:58:51 +05:30
|
|
|
}
|
|
|
|
',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
2018-08-07 13:47:18 +05:30
|
|
|
// Issue 5
|
2022-09-20 05:07:57 +05:30
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->bar();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->bar();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->bar();
|
|
|
|
else
|
|
|
|
$this->baz();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->bar();
|
|
|
|
else
|
|
|
|
$this->baz();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
for ($i = 0; $i < 3; $i++)
|
|
|
|
$this->bar();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
for ($i = 0; $i < 3; $i++)
|
|
|
|
$this->bar();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str)
|
|
|
|
$this->bar();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str)
|
|
|
|
$this->bar();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
while ($i < 10)
|
|
|
|
$this->bar();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
while ($i < 10)
|
|
|
|
$this->bar();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
do
|
|
|
|
$this->bar();
|
|
|
|
while ($i < 10);
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function foo()
|
|
|
|
{
|
|
|
|
do
|
|
|
|
$this->bar();
|
|
|
|
while ($i < 10);
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->foo();
|
|
|
|
else if ("a" === "c")
|
|
|
|
$this->bar();
|
|
|
|
else if ("a" === "d")
|
|
|
|
$this->baz();
|
|
|
|
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
if ("a" === "b")
|
|
|
|
$this->foo();
|
|
|
|
else if ("a" === "c")
|
|
|
|
$this->bar();
|
|
|
|
else if ("a" === "d")
|
|
|
|
$this->baz();
|
|
|
|
$a = "next statement";
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2022-09-20 05:07:57 +05:30
|
|
|
|
|
|
|
yield [
|
2018-08-07 13:47:18 +05:30
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str)
|
|
|
|
if ($str === "foo")
|
|
|
|
$this->bar();
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
'<?php
|
|
|
|
class Foo
|
|
|
|
{
|
|
|
|
public function bar()
|
|
|
|
{
|
|
|
|
foreach (["foo", "bar"] as $str)
|
|
|
|
if ($str === "foo")
|
|
|
|
$this->bar();
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
}',
|
|
|
|
];
|
2023-03-23 01:11:04 +05:30
|
|
|
|
|
|
|
yield [
|
|
|
|
'<?php
|
|
|
|
do {
|
|
|
|
$a = 123;
|
|
|
|
} while ($value > 10); // comment here
|
|
|
|
',
|
|
|
|
];
|
2018-04-17 23:58:51 +05:30
|
|
|
}
|
|
|
|
|
2022-09-20 05:07:57 +05:30
|
|
|
protected function createFixer(): AbstractFixer {
|
2018-04-17 23:58:51 +05:30
|
|
|
return new LineBreakAfterStatementsFixer();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|