1717use Illuminate \Foundation \Application ;
1818use InvalidArgumentException ;
1919use Laravel \SerializableClosure \SerializableClosure ;
20+ use RuntimeException ;
2021use UnitEnum ;
2122
2223final class FractionBuilder implements Arrayable
@@ -60,14 +61,13 @@ public function __invoke(...$arguments): mixed
6061 'closure ' => new SerializableClosure ($ this ->closure ),
6162 ]);
6263
63- $ instance = $ interpreter ->then ($ this ->then );
64-
65- if ($ this ->queued || $ this ->deferred || $ this ->rescued ) {
66- // @phpstan-ignore-next-line
67- $ interpreter ->configure ($ this ->queued ?->toArray() ?? $ this ->deferred ?->toArray() ?? $ this ->rescued ?->toArray());
64+ if ([$ has , $ configuration ] = $ this ->configuration ()) {
65+ if ($ has ) {
66+ $ interpreter ->configure ($ configuration );
67+ }
6868 }
6969
70- $ result = $ instance ->handle ($ this ->application );
70+ $ result = $ interpreter -> then ( $ this -> then ) ->handle ($ this ->application );
7171
7272 if ($ this ->queued || $ this ->deferred ) {
7373 return true ;
@@ -88,4 +88,26 @@ public function toArray(): array
8888 'rescued ' => $ this ->rescued ,
8989 ];
9090 }
91+
92+ /**
93+ * Determines which configurable should be applied.
94+ */
95+ private function configuration (): array
96+ {
97+ foreach ([
98+ $ this ->queued ,
99+ $ this ->deferred ,
100+ $ this ->rescued ,
101+ ] as $ instance ) {
102+ if ($ instance !== null ) {
103+ if (! $ instance instanceof Arrayable) {
104+ throw new RuntimeException (sprintf ('The instance of [%s] should implement Arrayable ' , class_basename ($ instance )));
105+ }
106+
107+ return [true , $ instance ->toArray ()];
108+ }
109+ }
110+
111+ return [false , []];
112+ }
91113}
0 commit comments