composer / satis

Simple static Composer repository generator - For a full private Composer repo use Private Packagist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught TypeError: substr_count() expects parameter 1 to be string

artmouse opened this issue · comments

PHP Fatal error:  Uncaught TypeError: substr_count() expects parameter 1 to be string, float given in /home/marbius/public_html/satis/src/PackageSelection/PackageSelection.php:751
Stack trace:
#0 /home/marbius/public_html/satis/src/PackageSelection/PackageSelection.php(751): substr_count(2.1, '+')
#1 /home/marbius/public_html/satis/src/PackageSelection/PackageSelection.php(189): Composer\Satis\PackageSelection\PackageSelection->selectLinks(Object(Composer\DependencyResolver\Pool), Array, true, true)
#2 /home/marbius/public_html/satis/src/Console/Command/BuildCommand.php(189): Composer\Satis\PackageSelection\PackageSelection->select(Object(Composer\Composer), true)
#3 /home/marbius/public_html/satis/vendor/symfony/console/Command/Command.php(256): Composer\Satis\Console\Command\BuildCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /home/marbius/public_html/satis/vendor/symfony/console/A in /home/marbius/public_html/satis/src/PackageSelection/PackageSelection.php on line 751

At the same time, the old version 2.0.0-dev works perfectly

Looks like a declare(strict_types=1); has been added in the code, without ensuring that the code is indeed compatible with strict types.

@alcohol I suggest going back to non-strict types, letting PHP perform the necessary type coercions (otherwise, the validation of the config files has to be a lot more complete that today, to validate types as well)

commented

@stof but it was added back in 2018...

commented

@artmouse can you please provide the information requested in the issue template? You've given us no way to reproduce or debug your issue currently.

ok, then the report is incomplete

How can i debug this piece of code to provide more information?
I have a lot of repositories specified in the satis.json file from which satis collects data. Many packages are duplicated.

@artmouse check whether you have a package somewhere defining a version field as a float rather than as a string.

One package have version not in string
version | 2.1 version | "2.0.2"

And how to fix this for yourself?

well, fix that package (and put a composer validate run in your CI to forbid putting invalid composer.json files in packages)

I do not know how to do that.
The package is located at a third-party vendor and most likely will not be fixed.

As a temporary measure ...

$prettyVersion = strval($package->getPrettyVersion());

And wrong package not added.

commented

Not sure what we should do about this. Probably just ignore invalid packages?

yeah, that would make sense