marcocesarato / php-conventional-changelog

A PHP tool built to generate a changelog from a project's commit messages and metadata following the conventionalcommits.org and automate versioning with semver.org.
GNU General Public License v3.0
230 stars 31 forks source link

fix: cast `Scope` as string to use it as array key #60

Closed aprat84 closed 1 year ago

aprat84 commented 1 year ago

Fixes the following error:

PHP Fatal error:  Uncaught TypeError: Illegal offset type in vendor/marcocesarato/php-conventional-changelog/src/Changelog.php:333

Stack trace:
#0 vendor/marcocesarato/php-conventional-changelog/src/DefaultCommand.php(200): ConventionalChangelog\Changelog->generate('/var/www/html', Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Style\SymfonyStyle))
#1 vendor/symfony/console/Command/Command.php(312): ConventionalChangelog\DefaultCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 vendor/symfony/console/Application.php(1022): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 vendor/symfony/console/Application.php(314): Symfony\Component\Console\Application->doRunCommand(Object(ConventionalChangelog\DefaultCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 vendor/symfony/console/Application.php(168): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 vendor/marcocesarato/php-conventional-changelog/conventional-changelog(33): Symfony\Component\Console\Application->run()
#6 vendor/bin/conventional-changelog(120): include('v...')
#7 {main}
  thrown in vendor/marcocesarato/php-conventional-changelog/src/Changelog.php on line 333

The cause is that you are using an object Scope as an array key, in lines 330 and 333 in file src/Changelog.php.

https://www.php.net/manual/en/language.types.array.php

Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.

So, as Scope implements Stringable, should be casted as (string) before using it as an array key.

PHP Version tested: 8.1.16

aprat84 commented 1 year ago

@marcocesarato can u review this please?