Skip to content

Commit

Permalink
refactor: fix code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodmain committed Jul 23, 2024
1 parent 5c465a9 commit d5fad34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
.phpunit.result.cache
vendor/
.php-cs-fixer.cache
cghooks.lock
3 changes: 1 addition & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(['docker', 'k8s', 'vendor', 'bootstrap/cache'])
->notPath(['_ide_helper.php', '_ide_helper_models.php'])
->exclude(['vendor', 'bootstrap/cache'])
->in(__DIR__);

$config = new PhpCsFixer\Config();
Expand Down
61 changes: 22 additions & 39 deletions src/HelpersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Maatwebsite\Excel\ExcelServiceProvider;
use RonasIT\Support\Contracts\VersionEnumContract;
use RonasIT\Support\Contracts\VersionEnumContract as Version;
use RonasIT\Support\Middleware\SecurityMiddleware;
use Illuminate\Routing\Router;

Expand Down Expand Up @@ -76,23 +76,23 @@ protected function extendRouter(): void
/**
* Specify that the route version must be in the range of given values inclusive.
*
* @param VersionEnumContract|null $start
* @param VersionEnumContract|null $end
* @param Version|null $start
* @param Version|null $end
* @param string|null $param (default is 'version')
* @param Route|null $instance
* @return Router|Route
*/
$versionRange = function (
?VersionEnumContract $start,
?VersionEnumContract $end,
?string $param,
Route $instance = null
?Version $start,
?Version $end,
?string $param,
Route $instance = null
) {
if (!$param) {
$param = 'version';
}

$versionEnum = app(VersionEnumContract::class);
$versionEnum = app(Version::class);
$disabledVersions = config('app.disabled_api_versions') ?: [];

$versions = array_diff($versionEnum::values(), $disabledVersions);
Expand All @@ -116,36 +116,19 @@ protected function extendRouter(): void
: RouteFacade::whereIn($param, $versions);
};

Route::macro('versionRange', fn (
VersionEnumContract $from,
VersionEnumContract $to,
$param = null
) => $versionRange($from, $to, $param, $this));
Route::macro('versionFrom', fn (
VersionEnumContract $from,
$param = null
) => $versionRange($from, null, $param, $this));
Route::macro('versionTo', fn (
VersionEnumContract $to,
$param = null
) => $versionRange(null, $to, $param, $this));

RouteFacade::macro('versionRange', fn (
VersionEnumContract $from,
VersionEnumContract $to,
string $param = null
) => $versionRange($from, $to, $param));
RouteFacade::macro('versionFrom', fn (
VersionEnumContract $from,
$param = null
) => $versionRange($from, null, $param));
RouteFacade::macro('versionTo', fn (
VersionEnumContract $to,
$param = null
) => $versionRange(null, $to, $param));

RouteFacade::macro('version', fn (
VersionEnumContract $version
) => RouteFacade::prefix('v' . $version->value));
Route::macro(
'versionRange',
fn (Version $from, Version $to, $param = null) => $versionRange($from, $to, $param, $this)
);
Route::macro('versionFrom', fn (Version $from, $param = null) => $versionRange($from, null, $param, $this));
Route::macro('versionTo', fn (Version $to, $param = null) => $versionRange(null, $to, $param, $this));

RouteFacade::macro(
'versionRange',
fn (Version $from, Version $to, string $param = null) => $versionRange($from, $to, $param)
);
RouteFacade::macro('versionFrom', fn (Version $from, $param = null) => $versionRange($from, null, $param));
RouteFacade::macro('versionTo', fn (Version $to, $param = null) => $versionRange(null, $to, $param));
RouteFacade::macro('version', fn (Version $version) => RouteFacade::prefix('v' . $version->value));
}
}

0 comments on commit d5fad34

Please sign in to comment.