A colleague is cloning a repo and getting the following error when running bake commands through our own plugin:
PHP Fatal error: Declaration of OurPlugin\Command\ModelCommand::findBelongsTo(Cake\ORM\Table $model, array $associations): array must be compatible with Bake\Command\ModelCommand::findBelongsTo(Cake\ORM\Table $model, array $associations, ?Cake\Console\Arguments $args = null): array in C:\Users\colleague_name_here\Downloads\xampp_php81\htdocs\OurApp\plugins\OurPlugin\src\Command\ModelCommand.php on line 334
I don't get that issue with my existing local copy. I was able to replicate cloning and duplicating to another folder. Where is that vendor change coming from?
In composer.json
:
"cakephp/bake": "^2.3",
vendor file, where the function definition seems to have changed
public function findBelongsTo(Table $model, array $associations, ?Arguments $args = null): array
Current plugin:
public function findBelongsTo(Table $model, array $associations): array
In GitHub, https://github.com/cakephp/bake/blob/2.3.0/src/Command/ModelCommand.php
public function findBelongsTo(Table $model, array $associations): array
This third argument was introduced in bake 2.9.0. Perhaps you have a composer.lock
that's locked to 2.8.0 or earlier and that's what everybody else is using, and that's what you deployed, so everything worked fine when you do composer install
-- but your colleague just ran a composer update
which brought them to the offending version 2.9.3.
Until the code is adjusted, you're probably best off just updating your composer.json
to specifically lock at exactly the last known working version, and then even a composer update
won't go past that:
"cakephp/bake": "2.8.3"
Once you get the code updated appropriately, change this to require 2.9.3 at a minimum and do composer update
again:
"cakephp/bake": "^2.9.3"