cakephp icon indicating copy to clipboard operation
cakephp copied to clipboard

Change return type of CommandInterface::run() and Command::execute().

Open ADmad opened this issue 3 years ago • 5 comments

Also make Command class abstract.

ADmad avatar Jul 06 '22 13:07 ADmad

The current int|null|void is ugly. Always returning an int from execute() shouldn't be too much trouble. We just need to update the bake template to include return static::CODE_SUCCESS.

ADmad avatar Jul 06 '22 13:07 ADmad

We just need to update the bake template to include return static::CODE_SUCCESS.

And update almost every command that exists both for us and in user-land code. I agree the current return type isn't great but this feels like a tedious to fix breaking change that doesn't make user land code safer.

markstory avatar Jul 06 '22 14:07 markstory

Maybe int|null then only?

dereuromark avatar Jul 06 '22 14:07 dereuromark

Personally I'd generally like to see CakePHP enforcing cleaner / more explicit userland code where possible, hence I'd welcome this change, even though upgrades might be a bit tedious if one has many and/or complex commands.

I gotta admit that I didn't really follow all the type upgrades that happened recently as I was very busy, so I'm not sure about the possible breaking changes that were already introduced... or better yet, not introduced for that matter. If it's a concern in the grand scheme of adding type hints, then at least upgrading the docblock type, the documentation and bake could be a first step, and in 6.x we could add the concrete return type?

ndm2 avatar Jul 06 '22 15:07 ndm2

The only thing I don't like is the return type cannot be declared since void cannot be in a union type.

othercorey avatar Jul 06 '22 19:07 othercorey

Are we going to abandon this for cake5?

othercorey avatar Oct 15 '22 02:10 othercorey