Существует ли инструмент командной строки (GNU / Linux) для стандартов кодирования PHP (с html-строкой)? - PullRequest
0 голосов
/ 03 июня 2019

Существует множество «стандартов для инструментов кодирования» для PHP, но я пробовал использовать phpcbf и php-cs-fixer , но они дали мне не очень хорошие результаты.

Например (с плохим ... очень плохим отступом):

<?php
// A example with a horrific indentation

$title = 'This is the title';
$rows = array(array('aaa', 'bbb', 'ccc'),
array('ddd', 'eee', 'fff'),
    array('ggg', 'hhh', 'iii'));

function print_rows($rows) {
    foreach ($rows as $row) {
?>
    <tr>
<?php
  foreach ($row as $cell) {
?>
<td><?=$cell?></td>
<?php
    }
?>
</tr>
<?php
}
}
?>
<html>
    <head>
<title>A example with a horrific indentation
</title>
</head>
<body>
    <h1>
<?php
echo $title;?></h1>


<table border="1">
<?php print_rows($rows);?>
</table>

    </body>
</html>

Ожидаемый результат должен быть (или близок к этому):

<?php
// A example with a horrific indentation

$title = 'This is the title';
$rows = array(
    array('aaa', 'bbb', 'ccc'),
    array('ddd', 'eee', 'fff'),
    array('ggg', 'hhh', 'iii'));

function print_rows($rows) {
    foreach ($rows as $row) {
    ?>
        <tr>
            <?php
            foreach ($row as $cell) {
            ?>
                <td><?=$cell?></td>
            <?php
            }
            ?>
        </tr>
    <?php
    }
}
?>

<html>
    <head>
        <title>A example with a horrific indentation</title>
    </head>
    <body>
        <h1>
            <?php
            echo $title;
            ?>
        </h1>
        <table border="1">
            <?php print_rows($rows);?>
        </table>
    </body>
</html>

Но с php-cs-fixer вывод:

$ php-cs-fixer fix example.php --rules=@PSR2

Это:

<?php
// A example with a horrific indentation

$title = 'This is the title';
$rows = array(array('aaa', 'bbb', 'ccc'),
array('ddd', 'eee', 'fff'),
    array('ggg', 'hhh', 'iii'));

function print_rows($rows)
{
    foreach ($rows as $row) {
        ?>
    <tr>
<?php
  foreach ($row as $cell) {
      ?>
<td><?=$cell?></td>
<?php
  } ?>
</tr>
<?php
    }
}
?>
<html>
    <head>
<title>A example with a horrific indentation
</title>
</head>
<body>
    <h1>
<?php
echo $title;?></h1>


<table border="1">
<?php print_rows($rows);?>
</table>

    </body>
</html>

И с phpcbf это:

<?php
// A example with a horrific indentation

$title = 'This is the title';
$rows = array(array('aaa', 'bbb', 'ccc'),
array('ddd', 'eee', 'fff'),
    array('ggg', 'hhh', 'iii'));

function print_rows($rows)
{
    foreach ($rows as $row) {
        ?>
    <tr>
        <?php
        foreach ($row as $cell) {
            ?>
<td><?=$cell?></td>
            <?php
        }
        ?>
</tr>
        <?php
    }
}
?>
<html>
    <head>
<title>A example with a horrific indentation
</title>
</head>
<body>
    <h1>
<?php
echo $title;?></h1>


<table border="1">
<?php print_rows($rows);?>
</table>

    </body>
</html>

Эти два инструмента только формат / отступкод PHP, но они не имеют ничего общего с встроенным HTML.

...