PHP code example of henry-wiki / sc-indent-fix

1. Go to this page and download the library: Download henry-wiki/sc-indent-fix library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

henry-wiki / sc-indent-fix example snippets




$fixer = new \henry_wiki\sc_indent_fix\sc_indent_fix();
$result = $fixer->process($code);

// Before
function render($items) {
$output[] = "<div>";
foreach ($items as $item) {
$output[] = "<p>" . $item . "</p>";
}
$output[] = "</div>";
return implode("\n", $output);
}

// After
function render($items) {
    $output[] = "<div>";
        foreach ($items as $item) {
            $output[] = "<p>" . $item . "</p>";
        }
    $output[] = "</div>";
    return implode("\n", $output);
}

// Before
if ($flag) {
echo "<div class='active'>";
echo "Enabled";
echo "</div>";
} else {
echo "<div class='inactive'>";
echo "Disabled";
echo "</div>";
}

// After
if ($flag) {
    echo "<div class='active'>";
        echo "Enabled";
    echo "</div>";
} else {
    echo "<div class='inactive'>";
        echo "Disabled";
    echo "</div>";
}

// Before
echo "<div>";
echo "<span>Hello</span>";
echo "</div>";

// After
echo "<div>";
    echo "<span>Hello</span>";
echo "</div>";

// Before
echo "<ul>";
foreach ($items as $item) {
echo "<li>" . $item . "</li>";
}
echo "</ul>";

// After
echo "<ul>";
    foreach ($items as $item) {
        echo "<li>";
            echo $item;
        echo "</li>";
    }
echo "</ul>";

// Before
switch ($type) {
case 1:
echo "<p>Type A</p>";
break;
case 2:
echo "<p>Type B</p>";
break;
default:
echo "<p>Unknown</p>";
}

// After
switch ($type) {
    case 1:
        echo "<p>Type A</p>";
        break;
    case 2:
        echo "<p>Type B</p>";
        break;
    default:
        echo "<p>Unknown</p>";
}

// Before
$html = "<div class='wrap'>
<table>
<tbody>
<tr>
<td>cell</td>
</tr>
</tbody>
</table>
</div>";

// After
$html = "<div class='wrap'>
    <table>
        <tbody>
            <tr>
                <td>cell</td>
            </tr>
        </tbody>
    </table>
</div>";

// Before
$sql = "SELECT
p.ProductId
FROM products p
WHERE p.Active = 1
AND p.Deleted = 0";

// After
$sql = "SELECT
        p.ProductId
    FROM products p
    WHERE p.Active = 1
        AND p.Deleted = 0";