Skip to content

Commit ab756e7

Browse files
Check heredoc/nowdoc indentation (#38)
1 parent 388b069 commit ab756e7

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

php-cs-fixer-rules.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
'import_constants' => true,
2929
'import_functions' => true,
3030
],
31+
'heredoc_indentation' => [
32+
'indentation' => 'start_plus_one',
33+
],
3134
'native_constant_invocation' => [
3235
'scope' => 'namespaced',
3336
'strict' => true,

tests/RulesTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ final class RulesTest extends TestCase
2727
// for `strlen()`.
2828
['global-function-not-imported.php', 'php-cs-fixer'],
2929
['global-constant-not-imported.php', 'php-cs-fixer'],
30+
// PHPCS doesn't seem to have a rule for heredoc/nowdoc indentation
31+
['NowdocNotIndented.php', 'phpcs'],
32+
['HeredocNotIndented.php', 'phpcs'],
3033
];
3134

3235
private static function phpCsFixerCommand(string $file): string
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test;
6+
7+
class HeredocNotIndented
8+
{
9+
private const MY_NOWDOC = <<<HEREDOC
10+
not indented!
11+
HEREDOC;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test;
6+
7+
class NowdocNotIndented
8+
{
9+
private const MY_NOWDOC = <<<'NOWDOC'
10+
not indented!
11+
NOWDOC;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test;
6+
7+
class PrivateConstHeredoc
8+
{
9+
private const MY_NOWDOC = <<<HEREDOC
10+
indented!
11+
HEREDOC;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test;
6+
7+
class PrivateConstNowdoc
8+
{
9+
private const MY_NOWDOC = <<<'NOWDOC'
10+
indented!
11+
NOWDOC;
12+
}

0 commit comments

Comments
 (0)