File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed
Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 1212
1313namespace App \Commands ;
1414
15+ use App \Exceptions \InvalidArgumentException ;
1516use Illuminate \Console \Application as Artisan ;
1617use Illuminate \Support \Facades \File ;
1718use LaravelZero \Framework \Commands \Command ;
@@ -258,7 +259,7 @@ private function getBinary(): string
258259 private function getTimeout (): ?float
259260 {
260261 if (! is_numeric ($ this ->option ('timeout ' ))) {
261- throw new \ InvalidArgumentException ('The timeout value must be a number. ' );
262+ throw new InvalidArgumentException ('The timeout value must be a number. ' );
262263 }
263264
264265 $ timeout = (float ) $ this ->option ('timeout ' );
Original file line number Diff line number Diff line change 1212
1313namespace App ;
1414
15+ use App \Exceptions \InvalidArgumentException ;
1516use App \Generators \BitoGenerator ;
1617use App \Generators \OpenAIChatGenerator ;
1718use App \Generators \OpenAIGenerator ;
@@ -45,17 +46,17 @@ protected function createDriver($driver)
4546 }
4647
4748 $ config = $ this ->config ->get ("ai-commit.generators. $ driver " );
48- $ class = sprintf ('App\Generators\%sGenerator ' , Str::studly ($ driver ));
49- if (class_exists ($ class )) {
50- return new $ class ($ config );
51- }
49+ $ studlyName = Str::studly ($ driver );
5250
53- $ method = 'create ' .Str::studly ($ driver ).'Driver ' ;
54- if (method_exists ($ this , $ method )) {
51+ if (method_exists ($ this , $ method = "create {$ studlyName }Driver " )) {
5552 return $ this ->{$ method }($ config );
5653 }
5754
58- throw new \InvalidArgumentException ("Driver [ $ driver] not supported. " );
55+ if (class_exists ($ class = "App \\Generators \\{$ studlyName }Generator " )) {
56+ return new $ class ($ config );
57+ }
58+
59+ throw new InvalidArgumentException ("Driver [ $ driver] not supported. " );
5960 }
6061
6162 private function createOpenAIDriver (array $ config ): OpenAIGenerator
Original file line number Diff line number Diff line change 1212
1313namespace App \Support ;
1414
15+ use App \Exceptions \RuntimeException ;
16+
1517/**
1618 * This file is modified from https://github.com/adhocore/php-json-fixer.
1719 */
@@ -276,7 +278,7 @@ private function fixOrFail(string $json): string
276278 return $ json ;
277279 }
278280
279- throw new \ RuntimeException (sprintf ('Could not fix JSON (tried padding `%s`) ' , substr ($ tmpJson , $ length )));
281+ throw new RuntimeException (sprintf ('Could not fix JSON (tried padding `%s`) ' , substr ($ tmpJson , $ length )));
280282 }
281283
282284 private function padLiteral (string $ tmpJson ): string
You can’t perform that action at this time.
0 commit comments