phpro / grumphp

A PHP code-quality tool
MIT License
4.15k stars 431 forks source link

Custom banners #237

Closed Grafikart closed 7 years ago

Grafikart commented 7 years ago
Q A
Branch master
Bug? yes

I tried to set custom banners but ended up with an error.

My configuration

# grumphp.yml
parameters:
  ascii:
    failed: ko.txt
    succeeded: ok.txt
  git_dir: .
  bin_dir: vendor/bin
  tasks:
    phplint: ~
    phpcsfixer2: ~
    phpunit:
      always_execute: true

Result:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to GrumPHP\Util\Filesystem::readFromFileInfo() must be an instance of SplFileInfo, string given

In my opinion you should allow string for this method https://github.com/phpro/grumphp/blob/master/src/GrumPHP/Util/Filesystem.php#L19 or convert information from configuration to SplFileInfo

veewee commented 7 years ago

@Grafikart That is indeed a bug that sneeked in with the 0.10.0 release. I've created a patch which will be included in next release. Thanks for noticing!

I'll close this issue for now, but feel free to create a PR for adding an ASCII string as value of the ascii paths. One option is to create an in-memory fileobject:

$file = new SplFileInfo('php://memory');
$content = $file->openFile('r+');
$content->fwrite('put ascii content here');
$content->rewind();

Another thing you could do is just use the string; The hard part will be detecting if the config contains strings or paths. Maybe we could use multiple parameters: one if you want to set the ascii path and another when you want to use an ascii string. Personally I prefer using a file, but I can image that some people want this in the configuration file.