Skip to content

Commit

Permalink
Revert to support minimum PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kitloong committed Jun 27, 2024
1 parent 8b8a2ea commit b539d35
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 22 additions & 7 deletions .github/workflows/phptest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="laravel-migrations-generator" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Custom code standard for Laravel Migrations Generator</description>
<description>Standard Based on PSR2</description>

<file>src</file>
<file>tests</file>
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/ExportRequestDocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/Controllers/LaravelRequestDocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/Doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Support\Arrayable;

/**
* @template-implements \Illuminate\Contracts\Support\Arrayable<string, mixed>
* @codeCoverageIgnore
*/
class Doc implements Arrayable
Expand Down Expand Up @@ -106,7 +105,7 @@ public function __construct(
string $httpMethod,
array $pathParameters,
array $rules,
string $docBlock,
string $docBlock
) {
$this->uri = $uri;
$this->methods = $methods;
Expand Down
22 changes: 14 additions & 8 deletions src/LaravelRequestDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

class LaravelRequestDocs
{
public function __construct(private RoutePath $routePath)
private RoutePath $routePath;

public function __construct(RoutePath $routePath)
{
$this->routePath = $routePath;
}

/**
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -253,7 +259,7 @@ public function appendRequestRules(Collection $docs): Collection

try {
$requestObject = $reflectionClass->newInstance();
} catch (Throwable) {
} catch (Throwable $ex) {
$requestObject = $reflectionClass->newInstanceWithoutConstructor();
}

Expand All @@ -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);
}
Expand All @@ -278,7 +284,7 @@ public function appendRequestRules(Collection $docs): Collection
$lrdDocComments[] = $requestMethodLrdComment;
$doc->mergeRules($requestMethodDocRules);
}
} catch (Throwable) {
} catch (Throwable $ex) {
// Do nothing.
}
}
Expand Down Expand Up @@ -335,15 +341,15 @@ 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;
}

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

foreach ($rule as $ruleItem) {
$rulesStrs[] = is_object($ruleItem) ? $ruleItem::class : $ruleItem;
$rulesStrs[] = is_object($ruleItem) ? get_class($ruleItem) : $ruleItem;
}

$rules[$attribute][] = implode("|", $rulesStrs);
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelRequestDocsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion tests/Stubs/TestControllers/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b539d35

Please sign in to comment.