pretty heredoc
, (*1)
It's painful to write heredocs in the middle of some indentation level:, (*2)
class CliApp
{
public static function printUsage()
{
echo <<<EOL
Usage:
linter [--fix] [--debug] <path>
linter (-h | --help)
linter --version
EOL;
}
}
Ruby has smart heredocs that respect indentation:, (*3)
class CliApp
def self.print_usage
puts <<~EOL
Usage:
linter [--fix] [--debug] <path>
linter (-h | --help)
linter --version
EOL
end
end
But PHP has not., (*4)
So I made a basic function that receives string and strips it:, (*5)
use function Sadovnik\PrettyHeredoc\ph as ✍️;
class CliApp
{
public static function printUsage()
{
echo ✍️('
Usage:
linter [--fix] [--debug] <path>
linter (-h | --help)
linter --version
');
}
}
Enjoy it!, (*6)
Install
Via Composer:, (*7)
composer require sadovnik/ph
⚓️, (*8)