diff --git a/.github/workflows/phplint.yml b/.github/workflows/phplint.yml index f1d7ab6..fcc6b88 100644 --- a/.github/workflows/phplint.yml +++ b/.github/workflows/phplint.yml @@ -24,7 +24,7 @@ jobs: coverage: pcov extensions: intl, gd, zip, pdo, sqlite, pdo_sqlite, dom, curl, libxml, mbstring, fileinfo, exif, iconv ini-values: memory_limit=-1,disable_functions="",pcov.exclude="~(vendor|tests|node_modules)~",pcov.directory="./" - php-version: 8.3 + php-version: 7.4 tools: composer:v2 - name: Composer Install diff --git a/.github/workflows/phptest.yml b/.github/workflows/phptest.yml index ad7bbde..e45cf85 100644 --- a/.github/workflows/phptest.yml +++ b/.github/workflows/phptest.yml @@ -9,14 +9,29 @@ jobs: strategy: matrix: - php: [8.2, 8.3] - laravel: ['10.*', '11.*'] + php: [7.4, 8.0, 8.1, 8.2, 8.3] + laravel: ['8.*', '11.*'] include: - - laravel: 8.* - php: 8.1 - - laravel: 9.* - php: 8.1 - - laravel: 10.* + - php: 8.0 + laravel: 9.* + - php: 8.1 + laravel: 9.* + - php: 8.2 + laravel: 9.* + - php: 8.1 + laravel: 10.* + - php: 8.2 + laravel: 10.* + - php: 8.3 + laravel: 10.* + - php: '8.2' + laravel: 11.* + exclude: + - laravel: 11.* + php: 7.4 + - laravel: 11.* + php: 8.0 + - laravel: 11.* php: 8.1 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/composer.json b/composer.json index 7ceffc3..888b0e6 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": "^8.1|^8.2|^8.3", + "php": "^7.4|^8.0|^8.1|^8.2|^8.3", "illuminate/contracts": "^8.37|^9.0|^10.0|^11.0", "kitloong/laravel-app-logger": "^1.0", "spatie/laravel-package-tools": "^1.4.3", diff --git a/phpcs.xml b/phpcs.xml index 42d9ffa..db4de98 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,6 @@ - Custom code standard for Laravel Migrations Generator + Standard Based on PSR2 src tests diff --git a/src/Commands/ExportRequestDocsCommand.php b/src/Commands/ExportRequestDocsCommand.php index 8f20806..660810e 100644 --- a/src/Commands/ExportRequestDocsCommand.php +++ b/src/Commands/ExportRequestDocsCommand.php @@ -31,8 +31,12 @@ class ExportRequestDocsCommand extends Command private string $exportFilePath; - public function __construct(LaravelRequestDocs $laravelRequestDoc, private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi) + private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi; + + public function __construct(LaravelRequestDocs $laravelRequestDoc, LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi) { + $this->laravelRequestDocsToOpenApi = $laravelRequestDocsToOpenApi; + parent::__construct(); $this->laravelRequestDocs = $laravelRequestDoc; diff --git a/src/Controllers/LaravelRequestDocsController.php b/src/Controllers/LaravelRequestDocsController.php index 2607486..974a6f5 100644 --- a/src/Controllers/LaravelRequestDocsController.php +++ b/src/Controllers/LaravelRequestDocsController.php @@ -8,15 +8,16 @@ use Illuminate\Routing\Controller; use Rakutentech\LaravelRequestDocs\LaravelRequestDocs; use Rakutentech\LaravelRequestDocs\LaravelRequestDocsToOpenApi; -use Symfony\Component\HttpFoundation\BinaryFileResponse; class LaravelRequestDocsController extends Controller { private LaravelRequestDocs $laravelRequestDocs; + private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi; - public function __construct(LaravelRequestDocs $laravelRequestDoc, private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi) + public function __construct(LaravelRequestDocs $laravelRequestDoc, LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi) { - $this->laravelRequestDocs = $laravelRequestDoc; + $this->laravelRequestDocsToOpenApi = $laravelRequestDocsToOpenApi; + $this->laravelRequestDocs = $laravelRequestDoc; } /** @@ -82,7 +83,11 @@ public function api(Request $request): JsonResponse /** * @codeCoverageIgnore */ - public function assets(Request $request): BinaryFileResponse|JsonResponse + + /** + * @return \Symfony\Component\HttpFoundation\BinaryFileResponse|\Illuminate\Http\JsonResponse + */ + public function assets(Request $request) { $path = explode('/', $request->path()); $path = end($path); diff --git a/src/Doc.php b/src/Doc.php index d60c8e0..b6ae167 100644 --- a/src/Doc.php +++ b/src/Doc.php @@ -5,7 +5,6 @@ use Illuminate\Contracts\Support\Arrayable; /** - * @template-implements \Illuminate\Contracts\Support\Arrayable * @codeCoverageIgnore */ class Doc implements Arrayable @@ -106,7 +105,7 @@ public function __construct( string $httpMethod, array $pathParameters, array $rules, - string $docBlock, + string $docBlock ) { $this->uri = $uri; $this->methods = $methods; diff --git a/src/LaravelRequestDocs.php b/src/LaravelRequestDocs.php index a371d72..8de677b 100644 --- a/src/LaravelRequestDocs.php +++ b/src/LaravelRequestDocs.php @@ -13,8 +13,11 @@ class LaravelRequestDocs { - public function __construct(private RoutePath $routePath) + private RoutePath $routePath; + + public function __construct(RoutePath $routePath) { + $this->routePath = $routePath; } /** @@ -29,7 +32,7 @@ public function getDocs( bool $showPut, bool $showPatch, bool $showDelete, - bool $showHead, + bool $showHead ): Collection { $filteredMethods = array_filter([ Request::METHOD_GET => $showGet, @@ -183,10 +186,13 @@ public function getControllersInfo(array $onlyMethods): Collection $pathParameters[$k] = [$v]; } + /** @var string[] $middlewares */ + $middlewares = $route->middleware(); + $doc = new Doc( $route->uri, $routeMethods, - config('request-docs.hide_meta_data') ? [] : $route->middleware(), + config('request-docs.hide_meta_data') ? [] : $middlewares, config('request-docs.hide_meta_data') ? '' : $controllerName, config('request-docs.hide_meta_data') ? '' : $controllerFullPath, config('request-docs.hide_meta_data') ? '' : $method, @@ -253,7 +259,7 @@ public function appendRequestRules(Collection $docs): Collection try { $requestObject = $reflectionClass->newInstance(); - } catch (Throwable) { + } catch (Throwable $ex) { $requestObject = $reflectionClass->newInstanceWithoutConstructor(); } @@ -265,7 +271,7 @@ public function appendRequestRules(Collection $docs): Collection try { $doc->mergeRules($this->flattenRules($requestObject->$requestMethod())); $requestReflectionMethod = new ReflectionMethod($requestObject, $requestMethod); - } catch (Throwable) { + } catch (Throwable $ex) { $doc->mergeRules($this->rulesByRegex($requestClassName, $requestMethod)); $requestReflectionMethod = new ReflectionMethod($requestClassName, $requestMethod); } @@ -278,7 +284,7 @@ public function appendRequestRules(Collection $docs): Collection $lrdDocComments[] = $requestMethodLrdComment; $doc->mergeRules($requestMethodDocRules); } - } catch (Throwable) { + } catch (Throwable $ex) { // Do nothing. } } @@ -335,7 +341,7 @@ public function flattenRules(array $mixedRules): array foreach ($mixedRules as $attribute => $rule) { if (is_object($rule)) { - $rules[$attribute][] = $rule::class; + $rules[$attribute][] = get_class($rule); continue; } @@ -343,7 +349,7 @@ public function flattenRules(array $mixedRules): array $rulesStrs = []; foreach ($rule as $ruleItem) { - $rulesStrs[] = is_object($ruleItem) ? $ruleItem::class : $ruleItem; + $rulesStrs[] = is_object($ruleItem) ? get_class($ruleItem) : $ruleItem; } $rules[$attribute][] = implode("|", $rulesStrs); diff --git a/src/LaravelRequestDocsMiddleware.php b/src/LaravelRequestDocsMiddleware.php index 80b209f..3821915 100644 --- a/src/LaravelRequestDocsMiddleware.php +++ b/src/LaravelRequestDocsMiddleware.php @@ -161,7 +161,7 @@ public function listenToModels(): void // split $event by : and take first part $event = explode(':', $event)[0]; $event = Str::replace('eloquent.', '', $event); - $class = $model::class; + $class = get_class($model); $this->modelsTimeline[] = [ 'event' => $event, diff --git a/tests/Stubs/TestControllers/WelcomeController.php b/tests/Stubs/TestControllers/WelcomeController.php index f979bbf..b572332 100644 --- a/tests/Stubs/TestControllers/WelcomeController.php +++ b/tests/Stubs/TestControllers/WelcomeController.php @@ -59,7 +59,10 @@ public function noRules(RequestWithoutRules $request): int return 1; } - public function health(mixed $unknown): int + /** + * @param mixed $unknown + */ + public function health($unknown): int { return 1; }