Heredoc alternative for text.

1.0.0 2016-12-05 09:12 UTC

This package is not auto-updated.

Last update: 2024-04-22 12:24:14 UTC


README

Build Status Code Climate Test Coverage Issue Count

It's painful to write heredocs in the middle of some indentation level:

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:

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.

So I made a basic function that receives string and strips it:

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!

Install

Via Composer:

composer require sadovnik/ph

⚓️