Skip to content

Commit b539d35

Browse files
committed
Revert to support minimum PHP 7.4
1 parent 8b8a2ea commit b539d35

File tree

10 files changed

+59
-27
lines changed

10 files changed

+59
-27
lines changed

.github/workflows/phplint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
coverage: pcov
2525
extensions: intl, gd, zip, pdo, sqlite, pdo_sqlite, dom, curl, libxml, mbstring, fileinfo, exif, iconv
2626
ini-values: memory_limit=-1,disable_functions="",pcov.exclude="~(vendor|tests|node_modules)~",pcov.directory="./"
27-
php-version: 8.3
27+
php-version: 7.4
2828
tools: composer:v2
2929

3030
- name: Composer Install

.github/workflows/phptest.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,29 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
php: [8.2, 8.3]
13-
laravel: ['10.*', '11.*']
12+
php: [7.4, 8.0, 8.1, 8.2, 8.3]
13+
laravel: ['8.*', '11.*']
1414
include:
15-
- laravel: 8.*
16-
php: 8.1
17-
- laravel: 9.*
18-
php: 8.1
19-
- laravel: 10.*
15+
- php: 8.0
16+
laravel: 9.*
17+
- php: 8.1
18+
laravel: 9.*
19+
- php: 8.2
20+
laravel: 9.*
21+
- php: 8.1
22+
laravel: 10.*
23+
- php: 8.2
24+
laravel: 10.*
25+
- php: 8.3
26+
laravel: 10.*
27+
- php: '8.2'
28+
laravel: 11.*
29+
exclude:
30+
- laravel: 11.*
31+
php: 7.4
32+
- laravel: 11.*
33+
php: 8.0
34+
- laravel: 11.*
2035
php: 8.1
2136

2237
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^8.1|^8.2|^8.3",
19+
"php": "^7.4|^8.0|^8.1|^8.2|^8.3",
2020
"illuminate/contracts": "^8.37|^9.0|^10.0|^11.0",
2121
"kitloong/laravel-app-logger": "^1.0",
2222
"spatie/laravel-package-tools": "^1.4.3",

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="laravel-migrations-generator" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3-
<description>Custom code standard for Laravel Migrations Generator</description>
3+
<description>Standard Based on PSR2</description>
44

55
<file>src</file>
66
<file>tests</file>

src/Commands/ExportRequestDocsCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ class ExportRequestDocsCommand extends Command
3131

3232
private string $exportFilePath;
3333

34-
public function __construct(LaravelRequestDocs $laravelRequestDoc, private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi)
34+
private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi;
35+
36+
public function __construct(LaravelRequestDocs $laravelRequestDoc, LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi)
3537
{
38+
$this->laravelRequestDocsToOpenApi = $laravelRequestDocsToOpenApi;
39+
3640
parent::__construct();
3741

3842
$this->laravelRequestDocs = $laravelRequestDoc;

src/Controllers/LaravelRequestDocsController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
use Illuminate\Routing\Controller;
99
use Rakutentech\LaravelRequestDocs\LaravelRequestDocs;
1010
use Rakutentech\LaravelRequestDocs\LaravelRequestDocsToOpenApi;
11-
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1211

1312
class LaravelRequestDocsController extends Controller
1413
{
1514
private LaravelRequestDocs $laravelRequestDocs;
15+
private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi;
1616

17-
public function __construct(LaravelRequestDocs $laravelRequestDoc, private LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi)
17+
public function __construct(LaravelRequestDocs $laravelRequestDoc, LaravelRequestDocsToOpenApi $laravelRequestDocsToOpenApi)
1818
{
19-
$this->laravelRequestDocs = $laravelRequestDoc;
19+
$this->laravelRequestDocsToOpenApi = $laravelRequestDocsToOpenApi;
20+
$this->laravelRequestDocs = $laravelRequestDoc;
2021
}
2122

2223
/**
@@ -82,7 +83,11 @@ public function api(Request $request): JsonResponse
8283
/**
8384
* @codeCoverageIgnore
8485
*/
85-
public function assets(Request $request): BinaryFileResponse|JsonResponse
86+
87+
/**
88+
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse|\Illuminate\Http\JsonResponse
89+
*/
90+
public function assets(Request $request)
8691
{
8792
$path = explode('/', $request->path());
8893
$path = end($path);

src/Doc.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Illuminate\Contracts\Support\Arrayable;
66

77
/**
8-
* @template-implements \Illuminate\Contracts\Support\Arrayable<string, mixed>
98
* @codeCoverageIgnore
109
*/
1110
class Doc implements Arrayable
@@ -106,7 +105,7 @@ public function __construct(
106105
string $httpMethod,
107106
array $pathParameters,
108107
array $rules,
109-
string $docBlock,
108+
string $docBlock
110109
) {
111110
$this->uri = $uri;
112111
$this->methods = $methods;

src/LaravelRequestDocs.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
class LaravelRequestDocs
1515
{
16-
public function __construct(private RoutePath $routePath)
16+
private RoutePath $routePath;
17+
18+
public function __construct(RoutePath $routePath)
1719
{
20+
$this->routePath = $routePath;
1821
}
1922

2023
/**
@@ -29,7 +32,7 @@ public function getDocs(
2932
bool $showPut,
3033
bool $showPatch,
3134
bool $showDelete,
32-
bool $showHead,
35+
bool $showHead
3336
): Collection {
3437
$filteredMethods = array_filter([
3538
Request::METHOD_GET => $showGet,
@@ -183,10 +186,13 @@ public function getControllersInfo(array $onlyMethods): Collection
183186
$pathParameters[$k] = [$v];
184187
}
185188

189+
/** @var string[] $middlewares */
190+
$middlewares = $route->middleware();
191+
186192
$doc = new Doc(
187193
$route->uri,
188194
$routeMethods,
189-
config('request-docs.hide_meta_data') ? [] : $route->middleware(),
195+
config('request-docs.hide_meta_data') ? [] : $middlewares,
190196
config('request-docs.hide_meta_data') ? '' : $controllerName,
191197
config('request-docs.hide_meta_data') ? '' : $controllerFullPath,
192198
config('request-docs.hide_meta_data') ? '' : $method,
@@ -253,7 +259,7 @@ public function appendRequestRules(Collection $docs): Collection
253259

254260
try {
255261
$requestObject = $reflectionClass->newInstance();
256-
} catch (Throwable) {
262+
} catch (Throwable $ex) {
257263
$requestObject = $reflectionClass->newInstanceWithoutConstructor();
258264
}
259265

@@ -265,7 +271,7 @@ public function appendRequestRules(Collection $docs): Collection
265271
try {
266272
$doc->mergeRules($this->flattenRules($requestObject->$requestMethod()));
267273
$requestReflectionMethod = new ReflectionMethod($requestObject, $requestMethod);
268-
} catch (Throwable) {
274+
} catch (Throwable $ex) {
269275
$doc->mergeRules($this->rulesByRegex($requestClassName, $requestMethod));
270276
$requestReflectionMethod = new ReflectionMethod($requestClassName, $requestMethod);
271277
}
@@ -278,7 +284,7 @@ public function appendRequestRules(Collection $docs): Collection
278284
$lrdDocComments[] = $requestMethodLrdComment;
279285
$doc->mergeRules($requestMethodDocRules);
280286
}
281-
} catch (Throwable) {
287+
} catch (Throwable $ex) {
282288
// Do nothing.
283289
}
284290
}
@@ -335,15 +341,15 @@ public function flattenRules(array $mixedRules): array
335341

336342
foreach ($mixedRules as $attribute => $rule) {
337343
if (is_object($rule)) {
338-
$rules[$attribute][] = $rule::class;
344+
$rules[$attribute][] = get_class($rule);
339345
continue;
340346
}
341347

342348
if (is_array($rule)) {
343349
$rulesStrs = [];
344350

345351
foreach ($rule as $ruleItem) {
346-
$rulesStrs[] = is_object($ruleItem) ? $ruleItem::class : $ruleItem;
352+
$rulesStrs[] = is_object($ruleItem) ? get_class($ruleItem) : $ruleItem;
347353
}
348354

349355
$rules[$attribute][] = implode("|", $rulesStrs);

src/LaravelRequestDocsMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function listenToModels(): void
161161
// split $event by : and take first part
162162
$event = explode(':', $event)[0];
163163
$event = Str::replace('eloquent.', '', $event);
164-
$class = $model::class;
164+
$class = get_class($model);
165165

166166
$this->modelsTimeline[] = [
167167
'event' => $event,

tests/Stubs/TestControllers/WelcomeController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function noRules(RequestWithoutRules $request): int
5959
return 1;
6060
}
6161

62-
public function health(mixed $unknown): int
62+
/**
63+
* @param mixed $unknown
64+
*/
65+
public function health($unknown): int
6366
{
6467
return 1;
6568
}

0 commit comments

Comments
 (0)