diff --git a/src/ApiRequestProxy.php b/src/ApiRequestProxy.php index 37edbe9..e33433c 100644 --- a/src/ApiRequestProxy.php +++ b/src/ApiRequestProxy.php @@ -11,10 +11,10 @@ use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Support\Traits\ForwardsCalls; -use Laragear\ApiManager\Attributes\UseResponse; use LogicException; use ReflectionMethod; use ReflectionProperty; + use function array_merge; use function array_splice; use function class_basename; @@ -72,19 +72,19 @@ protected function createRequest(): PendingRequest ->when( $this->api->authBasic(), static function (PendingRequest $request, array $auth): PendingRequest { - return $request->withBasicAuth(... $auth); + return $request->withBasicAuth(...$auth); } ) ->when( $this->api->authDigest(), static function (PendingRequest $request, array $auth): PendingRequest { - return $request->withDigestAuth(... $auth); + return $request->withDigestAuth(...$auth); } ) ->when( $this->api->authToken(), static function (PendingRequest $request, array|string $auth): PendingRequest { - return $request->withToken(... (array) $auth); + return $request->withToken(...(array) $auth); } ); @@ -99,7 +99,7 @@ static function (PendingRequest $request, array|string $auth): PendingRequest { public function on(Pool $pool, string $as = null): static { // We will have to retrieve by force the pool values. - $handler = tap((new ReflectionProperty($pool, 'handler')))->setAccessible(true)->getValue($pool); + $handler = tap(new ReflectionProperty($pool, 'handler'))->setAccessible(true)->getValue($pool); $requests = (new ReflectionProperty($pool, 'pool')); $request = $this->getApiRequest()->setHandler($handler)->async(); @@ -163,8 +163,9 @@ protected function executeApiAction(string $name, string $action, array $paramet /** * Wrap the response or promise into a custom response if found. * - * @param mixed $response - * @param string $name + * @param mixed $response + * @param string $name + * * @return mixed */ protected function wrapResponse(mixed $response, string $name): mixed diff --git a/src/ApiServer.php b/src/ApiServer.php index c5acc28..16f2be6 100644 --- a/src/ApiServer.php +++ b/src/ApiServer.php @@ -5,6 +5,7 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Tappable; + use function app; abstract class ApiServer @@ -50,7 +51,8 @@ abstract public function getBaseUrl(); /** * Modify a pristine new Pending Request. * - * @param \Illuminate\Http\Client\PendingRequest $request + * @param \Illuminate\Http\Client\PendingRequest $request + * * @return \Illuminate\Http\Client\PendingRequest|null|void */ public function beforeBuild(PendingRequest $request) @@ -61,7 +63,8 @@ public function beforeBuild(PendingRequest $request) /** * Modify Pending Request after its bootstrapped. * - * @param \Illuminate\Http\Client\PendingRequest $request + * @param \Illuminate\Http\Client\PendingRequest $request + * * @return \Illuminate\Http\Client\PendingRequest|null|void */ public function afterBuild(PendingRequest $request) @@ -74,7 +77,8 @@ public function afterBuild(PendingRequest $request) * * @deprecated Use `afterBuild()` instead. * - * @param \Illuminate\Http\Client\PendingRequest $request + * @param \Illuminate\Http\Client\PendingRequest $request + * * @return \Illuminate\Http\Client\PendingRequest|null|void */ public function build(PendingRequest $request) diff --git a/src/Console/Commands/MakeApi.php b/src/Console/Commands/MakeApi.php index 7ceb03c..e94e9a0 100644 --- a/src/Console/Commands/MakeApi.php +++ b/src/Console/Commands/MakeApi.php @@ -5,6 +5,7 @@ use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; + use function class_basename; use function file_exists; use function str_replace; @@ -40,7 +41,8 @@ class MakeApi extends GeneratorCommand /** * Build the class with the given name. * - * @param string $name + * @param string $name + * * @return string */ protected function buildClass($name) @@ -55,7 +57,7 @@ protected function buildClass($name) */ protected function rootNamespace() { - return $this->laravel->getNamespace() . 'Http\Apis\\'; + return $this->laravel->getNamespace().'Http\Apis\\'; } /** @@ -67,7 +69,7 @@ protected function getPath($name) { $name = Str::replaceFirst($this->laravel->getNamespace(), '', $name); - return $this->laravel['path'].'/'. str_replace('\\', '/', $name).'.php'; + return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'.php'; } /** diff --git a/src/Console/Commands/MakeApiResponse.php b/src/Console/Commands/MakeApiResponse.php index 6150c1f..b3146e5 100644 --- a/src/Console/Commands/MakeApiResponse.php +++ b/src/Console/Commands/MakeApiResponse.php @@ -6,6 +6,7 @@ use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; + use function file_exists; /** @@ -38,9 +39,9 @@ class MakeApiResponse extends GeneratorCommand /** * Execute the console command. * - * @return bool|null - * * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException + * + * @return bool|null */ public function handle() { @@ -59,7 +60,7 @@ protected function apiDoesntExists(): bool { $api = Str::ucfirst($this->argument('api')); - return ! file_exists($this->getPath($this->laravel->getNamespace() . "Http\Apis\\$api")); + return !file_exists($this->getPath($this->laravel->getNamespace()."Http\Apis\\$api")); } /** @@ -89,7 +90,7 @@ protected function rootNamespace() { $api = Str::studly($this->argument('api')); - return $this->laravel->getNamespace() . "Http\Apis\\$api\\Responses\\"; + return $this->laravel->getNamespace()."Http\Apis\\$api\\Responses\\"; } /** @@ -131,7 +132,7 @@ protected function getArguments() { return [ ['api', InputArgument::REQUIRED, 'The name of the API for the namespace of the custom response'], - ['name', InputArgument::REQUIRED, 'The name of the '.strtolower($this->type)] + ['name', InputArgument::REQUIRED, 'The name of the '.strtolower($this->type)], ]; } diff --git a/tests/ApiRequestProxyTest.php b/tests/ApiRequestProxyTest.php index 121943b..d8c08a3 100644 --- a/tests/ApiRequestProxyTest.php +++ b/tests/ApiRequestProxyTest.php @@ -11,6 +11,7 @@ use Laragear\ApiManager\ApiServer; use LogicException; use PHPUnit\Framework\Attributes\Test; + use function func_get_args; class ApiRequestProxyTest extends TestCase @@ -86,6 +87,7 @@ public function builds_on_inline_action_get(): void Http::assertSent(static function (Request $request): bool { static::assertSame('GET', $request->method()); static::assertSame('https://www.test.com/foo/action', $request->url()); + return true; }); } @@ -100,6 +102,7 @@ public function builds_on_inline_action_with_get_verb(): void Http::assertSent(static function (Request $request): bool { static::assertSame('GET', $request->method()); static::assertSame('https://www.test.com/bar/action', $request->url()); + return true; }); } @@ -113,6 +116,7 @@ public function builds_on_inline_action_using_camel_case(): void Http::assertSent(static function (Request $request): bool { static::assertSame('https://www.test.com/baz/quz', $request->url()); + return true; }); } @@ -127,6 +131,7 @@ public function builds_on_inline_action_using_http_verb(): void Http::assertSent(static function (Request $request): bool { static::assertSame('POST', $request->method()); static::assertSame('https://www.test.com/baz/quz', $request->url()); + return true; }); } @@ -141,6 +146,7 @@ public function builds_on_inline_action_with_url_parameters(): void Http::assertSent(static function (Request $request): bool { static::assertSame('POST', $request->method()); static::assertSame('https://www.test.com/baz/quz/10', $request->url()); + return true; }); } @@ -157,6 +163,7 @@ public function builds_on_inline_action_with_hacky_verb_and_path(): void Http::assertSent(static function (Request $request): bool { static::assertSame('GET', $request->method()); static::assertSame('www.google.com/test', $request->url()); + return true; }); } @@ -223,6 +230,7 @@ public function forwards_calls_to_the_request(): void Http::assertSent(static function (Request $request): bool { static::assertSame('GET', $request->method()); static::assertSame('www.google.com/test', $request->url()); + return true; }); } @@ -256,6 +264,7 @@ public function forwards_properties_to_api_server_inline_action(): void Http::assertSent(static function (Request $request): bool { static::assertSame('GET', $request->method()); static::assertSame('https://www.test.com/foo/action', $request->url()); + return true; }); } @@ -456,14 +465,14 @@ public function getBaseUrl(): string } public $actions = [ - 'foo' => 'foo/action', - 'bar' => 'get:bar/action', - 'baz quz' => 'post:baz/quz', - 'parameter' => 'post:baz/quz/{id}', - 'invalid' => 'invalid:/something', - 'hacky' => 'baseUrl:www.google.com', - 'override' => 'get:/not-overridden', - 'as property' => 'get:/not-overridden-property' + 'foo' => 'foo/action', + 'bar' => 'get:bar/action', + 'baz quz' => 'post:baz/quz', + 'parameter' => 'post:baz/quz/{id}', + 'invalid' => 'invalid:/something', + 'hacky' => 'baseUrl:www.google.com', + 'override' => 'get:/not-overridden', + 'as property' => 'get:/not-overridden-property', ]; public function override(PendingRequest $request, string $message) @@ -565,7 +574,7 @@ public function example(PendingRequest $request) class TestAuthWrapRequestServerAction extends ApiServer { public $actions = [ - 'example' => '200' + 'example' => '200', ]; public $responses = [ diff --git a/tests/ApiServerTest.php b/tests/ApiServerTest.php index 342fcb9..f20a409 100644 --- a/tests/ApiServerTest.php +++ b/tests/ApiServerTest.php @@ -12,7 +12,6 @@ public function builds_itself(): void { static::assertInstanceOf(TestSelfRegistrableApiServer::class, TestSelfRegistrableApiServer::api()->api); } - } class TestSelfRegistrableApiServer extends ApiServer diff --git a/tests/Fixtures/CustomResponse.php b/tests/Fixtures/CustomResponse.php index 6a0825a..a779616 100644 --- a/tests/Fixtures/CustomResponse.php +++ b/tests/Fixtures/CustomResponse.php @@ -6,5 +6,4 @@ class CustomResponse extends Response { - } diff --git a/tests/TestCase.php b/tests/TestCase.php index 9c70f80..cdae941 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,6 @@ namespace Tests; use Laragear\ApiManager\ApiManagerServiceProvider; -use Laragear\ApiManager\Facades\Api; use Orchestra\Testbench\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase @@ -11,7 +10,8 @@ abstract class TestCase extends BaseTestCase /** * Get package providers. * - * @param \Illuminate\Foundation\Application $app + * @param \Illuminate\Foundation\Application $app + * * @return array */ protected function getPackageProviders($app)