You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've just had a user report an error due to the getSolution method using an incorrect return type.
Previous to the recent solutions refactor, the RunnableSolution interface (which in our case, is implemented by the EnableStatamicPro class) extended the Solution interface, which meant the Solution return type would work.
However, after the solutions refactor, the legacy RunnableSolution interface now extends the newRunnableSolution interface, and it extends the newSolution contract.
Since it's no longer returning the legacy Solution contract (which we're using as our return type), users who hit that exception will see an error about the incorrect return type:
Statamic\Exceptions\StatamicProRequiredException::getSolution(): Return value must be of type Spatie\Ignition\Contracts\Solution, Statamic\Ignition\Solutions\EnableStatamicPro returned
One possible fix for this issue would be to re-add the relevant methods to the legacyRunnableSolution interface, then have it extend the legacySolution interface, to fix the return type error.
Alternativley, on our end, we could just update the return type on our end to expect RunnableSolution, instead of Solution. However, this wouldn't fix the issue for other apps/packages implementing their own runnable solutions.
How to reproduce the bug
Create a fresh Laravel app
Require spatie/laravel-ignition (which in turn, requires this package)
Create a runnable solution, which implements the legacyRunnableSolution interface
Create an exception, which implements the ProvidesSolution interface with a getSolution method. All imports pointing to the legacy Ignition namespace.
See a return type error when the exception is thrown
What happened?
We have a few "runnable solutions" in our package, implementing the legacy Ignition contracts.
For context, here's one of the exceptions we're returning a runnable solution from:
We've just had a user report an error due to the
getSolution
method using an incorrect return type.Previous to the recent solutions refactor, the
RunnableSolution
interface (which in our case, is implemented by theEnableStatamicPro
class) extended theSolution
interface, which meant theSolution
return type would work.However, after the solutions refactor, the legacy
RunnableSolution
interface now extends the newRunnableSolution
interface, and it extends the newSolution
contract.Since it's no longer returning the legacy
Solution
contract (which we're using as our return type), users who hit that exception will see an error about the incorrect return type:One possible fix for this issue would be to re-add the relevant methods to the legacy
RunnableSolution
interface, then have it extend the legacySolution
interface, to fix the return type error.Alternativley, on our end, we could just update the return type on our end to expect
RunnableSolution
, instead ofSolution
. However, this wouldn't fix the issue for other apps/packages implementing their own runnable solutions.How to reproduce the bug
spatie/laravel-ignition
(which in turn, requires this package)RunnableSolution
interfaceProvidesSolution
interface with agetSolution
method. All imports pointing to the legacy Ignition namespace.For ease, I've just ran through these steps for you and pushed up an example repo: https://github.com/duncanmcclean/spatie-ignition-runnable-solutions-return-type-error
Package Version
1.0.4
PHP Version
8.3.0
Which operating systems does with happen with?
macOS
Notes
Related: statamic/cms#10416
The text was updated successfully, but these errors were encountered: