Skip to content

DefaultIO raised a deprecation on PHP trim call #290

@llaville

Description

@llaville

Hello @sebastianfeldmann

I'm currently working on a new CaptainHook Plugin (that I think, it may be useful for the Community), and I found some core issues during my tests.

About: CaptainHook 5.28.0

I'll open reports now.

First one is

Trying to retrieve getStandardInput values from DefaultIO inside the beforeHook

For example

use CaptainHook\App\Config;
use CaptainHook\App\Plugin;
use CaptainHook\App\Runner\Hook as RunnerHook;

class BinPlugin extends Plugin\Hook\Base implements Plugin\Hook
{
    public function beforeHook(RunnerHook $hook): void
    {
        $stdInput = $this->io->getStandardInput();
    }
}

I got this PHP error

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /shared/backups/bartlett/captainhook-bin-plugin/vendor/captainhook/captainhook/src/Console/IO/DefaultIO.php on line 112

My patch to fix it, could be :

    public function getStandardInput(): array
    {
        if (empty($this->stdIn)) {
            if (empty($this->input->getOption('input'))) {
                $this->stdIn = $this->input->getOptions();
            } else {
                $this->stdIn = explode(PHP_EOL, trim($this->input->getOption('input'), '"'));
            }
        }
        return $this->stdIn;
    }

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions