cpliakas / git-wrapper

A PHP wrapper around the Git command line utility.
MIT License
505 stars 68 forks source link

v3.0.1: strlen() expects parameter 1 to be string, integer given #200

Closed hostep closed 4 years ago

hostep commented 4 years ago

Hi!

I just attempted upgrading from version 2.2.0 to 3.0.1 (an up-to-date changelog would handy btw, but no pressure 😉) and I ran into this error:

In GitCommand.php line 182:

  strlen() expects parameter 1 to be string, integer given

This happened when calling the log method on a GitWorkingCopy instance:

$this->git->log(
    [
        'shortstat' => true,
        'n' => self::LAST_COMMIT_COUNT,
        'date' => 'unix',
    ]
);

It interprets xxx in the argument -n xxx as an integer and calling strlen on an integer throws the above error. Probably due to strict_types being enabled.

Suggested would be to change:

        return array_filter($command, function ($value): bool {
            return strlen($value) > 0;
        });

to

        return array_filter($command, function ($value): bool {
            return strlen((string) $value) > 0;
        });

Does this make sense?

Thanks!

GrahamCampbell commented 4 years ago

I don't think that's what we actually want. I think we should fix the caller so it only calls this method with the correct types.

GrahamCampbell commented 4 years ago

A formal change log is provided at https://github.com/cpliakas/git-wrapper/blob/master/upgrade/rector/git-wrapper-30.yaml.

GrahamCampbell commented 4 years ago

I don't think that's what we actually want. I think we should fix the caller so it only calls this method with the correct types.

Actually, there does seem to a bug here, with this. I think the return type of this method is also wrong...

GrahamCampbell commented 4 years ago

Does https://github.com/cpliakas/git-wrapper/pull/201 fix your issue?

hostep commented 4 years ago

201 fixes the issue indeed, thanks for looking into this so quickly!