Heredoc alternative for text.

Maintainers

Details

github.com/sadovnik/ph

Source

Issues

Installs: 9

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/sadovnik/ph

1.0.0 2016-12-05 09:12 UTC

This package is not auto-updated.

Last update: 2025-10-20 19:41:44 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

⚓️