Skip to content

sadovnik/ph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pretty heredoc

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

⚓️