From a5921770f082921021009710a5849f948615d736 Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Wed, 14 Oct 2020 09:48:45 +0800 Subject: [PATCH] use PHP 7.4 syntaxes --- app/Console/Commands/UpdateCommand.php | 6 +- app/Events/PluginBootFailed.php | 3 +- app/Exceptions/Handler.php | 8 +-- app/Http/Controllers/AdminController.php | 26 ++----- app/Http/Controllers/ClosetController.php | 17 ++--- .../Controllers/NotificationsController.php | 12 ++-- app/Http/Controllers/SkinlibController.php | 25 +++---- app/Http/View/Composers/FootComposer.php | 15 ++-- app/Http/View/Composers/HeadComposer.php | 12 ++-- .../View/Composers/LanguagesMenuComposer.php | 7 +- app/Http/View/Composers/SideMenuComposer.php | 24 +++---- app/Http/View/Composers/UserMenuComposer.php | 6 +- app/Http/View/Composers/UserPanelComposer.php | 6 +- app/Listeners/CleanUpFrontEndLocaleFiles.php | 3 +- app/Listeners/CopyPluginAssets.php | 3 +- app/Listeners/SetAppLocale.php | 3 +- app/Services/Hook.php | 8 +-- app/Services/Option.php | 6 +- app/Services/OptionForm.php | 2 +- app/Services/Plugin.php | 23 +++--- app/Services/PluginManager.php | 72 +++++++------------ app/Services/Translations/JavaScript.php | 26 ++----- app/Services/Translations/Yaml.php | 3 +- app/Services/Unzip.php | 6 +- app/Services/Webpack.php | 7 +- tests/ExceptionsTests/HandlerTest.php | 6 +- tests/Fakes/Filter.php | 6 +- tests/ServicesTest/OptionFormTest.php | 4 +- tests/ServicesTest/PluginManagerTest.php | 4 +- 29 files changed, 123 insertions(+), 226 deletions(-) diff --git a/app/Console/Commands/UpdateCommand.php b/app/Console/Commands/UpdateCommand.php index 7a19ae15..bbf89a18 100644 --- a/app/Console/Commands/UpdateCommand.php +++ b/app/Console/Commands/UpdateCommand.php @@ -37,10 +37,8 @@ class UpdateCommand extends Command protected function procedures() { return collect([ - '0.0.1' => function () { - // this is just for testing - event('__0.0.1'); - }, + // this is just for testing + '0.0.1' => fn () => event('__0.0.1'), '5.0.0' => function () { if (option('home_pic_url') === './app/bg.jpg') { option(['home_pic_url' => './app/bg.webp']); diff --git a/app/Events/PluginBootFailed.php b/app/Events/PluginBootFailed.php index ab7cc775..51ca2dc4 100644 --- a/app/Events/PluginBootFailed.php +++ b/app/Events/PluginBootFailed.php @@ -6,8 +6,7 @@ use App\Services\Plugin; class PluginBootFailed extends Event { - /** @var Plugin */ - public $plugin; + public Plugin $plugin; public function __construct(Plugin $plugin) { diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 0e448c2c..9f892563 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -41,12 +41,8 @@ class Handler extends ExceptionHandler 'message' => $e->getMessage(), 'exception' => true, 'trace' => collect($e->getTrace()) - ->map(function ($trace) { - return Arr::only($trace, ['file', 'line']); - }) - ->filter(function ($trace) { - return Arr::has($trace, 'file'); - }) + ->map(fn ($trace) => Arr::only($trace, ['file', 'line'])) + ->filter(fn ($trace) => Arr::has($trace, 'file')) ->map(function ($trace) { $trace['file'] = str_replace(base_path().DIRECTORY_SEPARATOR, '', $trace['file']); diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 30220195..ab0ec9af 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -47,25 +47,13 @@ class AdminController extends Controller public function chartData() { - $xAxis = Collection::times(31, function ($i) { - return Carbon::today()->subDays(31 - $i)->format('m-d'); - }); + $xAxis = Collection::times(31, fn ($i) => Carbon::today()->subDays(31 - $i)->format('m-d')); $oneMonthAgo = Carbon::today()->subMonth(); - $grouping = function ($field) { - return function ($item) use ($field) { - return substr($item->$field, 5, 5); - }; - }; - $mapping = function ($item) { - return count($item); - }; - $aligning = function ($data) { - return function ($day) use ($data) { - return $data->get($day) ?? 0; - }; - }; + $grouping = fn ($field) => fn ($item) => substr($item->$field, 5, 5); + $mapping = fn ($item) => count($item); + $aligning = fn ($data) => fn ($day) => ($data->get($day) ?? 0); $userRegistration = User::where('register_at', '>=', $oneMonthAgo) ->select('register_at') @@ -105,9 +93,9 @@ class AdminController extends Controller 'pgsql' => 'PostgreSQL', ], config('database.default'), ''); - $enabledPlugins = $plugins->getEnabledPlugins()->map(function ($plugin) { - return ['title' => trans($plugin->title), 'version' => $plugin->version]; - }); + $enabledPlugins = $plugins->getEnabledPlugins()->map(fn ($plugin) => [ + 'title' => trans($plugin->title), 'version' => $plugin->version, + ]); if ($filesystem->exists(base_path('.git'))) { $process = new \Symfony\Component\Process\Process( diff --git a/app/Http/Controllers/ClosetController.php b/app/Http/Controllers/ClosetController.php index f206505d..ef950297 100644 --- a/app/Http/Controllers/ClosetController.php +++ b/app/Http/Controllers/ClosetController.php @@ -51,14 +51,15 @@ class ClosetController extends Controller return $user ->closet() - ->when($category === 'cape', function (Builder $query) { - return $query->where('type', 'cape'); - }, function (Builder $query) { - return $query->whereIn('type', ['steve', 'alex']); - }) - ->when($request->input('q'), function (Builder $query, $search) { - return $query->like('item_name', $search); - }) + ->when( + $category === 'cape', + fn (Builder $query) => $query->where('type', 'cape'), + fn (Builder $query) => $query->whereIn('type', ['steve', 'alex']), + ) + ->when( + $request->input('q'), + fn (Builder $query, $search) => $query->like('item_name', $search) + ) ->paginate((int) $request->input('perPage', 6)); } diff --git a/app/Http/Controllers/NotificationsController.php b/app/Http/Controllers/NotificationsController.php index e07d3cbf..5202d918 100644 --- a/app/Http/Controllers/NotificationsController.php +++ b/app/Http/Controllers/NotificationsController.php @@ -45,12 +45,12 @@ class NotificationsController extends Controller public function all() { - return auth()->user()->unreadNotifications->map(function ($notification) { - return [ + return auth()->user() + ->unreadNotifications + ->map(fn ($notification) => [ 'id' => $notification->id, 'title' => $notification->data['title'], - ]; - }); + ]); } public function read($id) @@ -58,9 +58,7 @@ class NotificationsController extends Controller $notification = auth() ->user() ->unreadNotifications - ->first(function ($notification) use ($id) { - return $notification->id === $id; - }); + ->first(fn ($notification) => $notification->id === $id); $notification->markAsRead(); $converter = new GithubFlavoredMarkdownConverter(); diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index f01b4de8..8a434dc7 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -68,17 +68,13 @@ class SkinlibController extends Controller $sortBy = $sort == 'time' ? 'upload_at' : $sort; return Texture::orderBy($sortBy, 'desc') - ->when($type === 'skin', function (Builder $query) { - return $query->whereIn('type', ['steve', 'alex']); - }, function (Builder $query) use ($type) { - return $query->where('type', $type); - }) - ->when($keyword, function (Builder $query, $keyword) { - return $query->like('name', $keyword); - }) - ->when($uploader, function (Builder $query, $uploader) { - return $query->where('uploader', $uploader); - }) + ->when( + $type === 'skin', + fn (Builder $query) => $query->whereIn('type', ['steve', 'alex']), + fn (Builder $query) => $query->where('type', $type), + ) + ->when($keyword, fn (Builder $query, $keyword) => $query->like('name', $keyword)) + ->when($uploader, fn (Builder $query, $uploader) => $query->where('uploader', $uploader)) ->when($user, function (Builder $query, User $user) { if (!$user->isAdmin()) { // use closure-style `where` clause to lift up SQL priority @@ -262,10 +258,9 @@ class SkinlibController extends Controller $user = Auth::user(); $duplicated = Texture::where('hash', $hash) - ->where(function ($query) use ($user) { - return $query->where('public', true) - ->orWhere('uploader', $user->uid); - }) + ->where( + fn (Builder $query) => $query->where('public', true)->orWhere('uploader', $user->uid) + ) ->first(); if ($duplicated) { // if the texture already uploaded was set to private, diff --git a/app/Http/View/Composers/FootComposer.php b/app/Http/View/Composers/FootComposer.php index a7b1c0df..9fc26954 100644 --- a/app/Http/View/Composers/FootComposer.php +++ b/app/Http/View/Composers/FootComposer.php @@ -12,20 +12,15 @@ use Illuminate\View\View; class FootComposer { - /** @var Request */ - protected $request; + protected Request $request; - /** @var Webpack */ - protected $webpack; + protected Webpack $webpack; - /** @var JavaScript */ - protected $javascript; + protected JavaScript $javascript; - /** @var Dispatcher */ - protected $dispatcher; + protected Dispatcher $dispatcher; - /** @var Filter */ - protected $filter; + protected Filter $filter; public function __construct( Request $request, diff --git a/app/Http/View/Composers/HeadComposer.php b/app/Http/View/Composers/HeadComposer.php index 2b2746c0..188be8a8 100644 --- a/app/Http/View/Composers/HeadComposer.php +++ b/app/Http/View/Composers/HeadComposer.php @@ -12,17 +12,13 @@ use Illuminate\View\View; class HeadComposer { - /** @var Webpack */ - protected $webpack; + protected Webpack $webpack; - /** @var Dispatcher */ - protected $dispatcher; + protected Dispatcher $dispatcher; - /** @var Request */ - protected $request; + protected Request $request; - /** @var Filter */ - protected $filter; + protected Filter $filter; public function __construct( Webpack $webpack, diff --git a/app/Http/View/Composers/LanguagesMenuComposer.php b/app/Http/View/Composers/LanguagesMenuComposer.php index d0bc6404..89b80496 100644 --- a/app/Http/View/Composers/LanguagesMenuComposer.php +++ b/app/Http/View/Composers/LanguagesMenuComposer.php @@ -8,8 +8,7 @@ use Illuminate\View\View; class LanguagesMenuComposer { - /** @var Request */ - protected $request; + protected Request $request; public function __construct(Request $request) { @@ -22,9 +21,7 @@ class LanguagesMenuComposer $path = $this->request->path(); $langs = collect(config('locales')) - ->reject(function ($locale) { - return Arr::has($locale, 'alias'); - }) + ->reject(fn ($locale) => Arr::has($locale, 'alias')) ->map(function ($locale, $id) use ($query, $path) { $query = array_merge($query, ['lang' => $id]); $locale['url'] = url($path.'?'.http_build_query($query)); diff --git a/app/Http/View/Composers/SideMenuComposer.php b/app/Http/View/Composers/SideMenuComposer.php index c609d706..deb8d535 100644 --- a/app/Http/View/Composers/SideMenuComposer.php +++ b/app/Http/View/Composers/SideMenuComposer.php @@ -3,6 +3,7 @@ namespace App\Http\View\Composers; use App\Events; +use App\Services\Plugin; use App\Services\PluginManager; use Blessing\Filter; use Illuminate\Http\Request; @@ -11,11 +12,9 @@ use Illuminate\View\View; class SideMenuComposer { - /** @var Request */ - protected $request; + protected Request $request; - /** @var Filter */ - protected $filter; + protected Filter $filter; public function __construct(Request $request, Filter $filter) { @@ -44,9 +43,7 @@ class SideMenuComposer $menu = $menu[$type]; $menu = $this->filter->apply('side_menu', $menu, [$type]); - $view->with('items', array_map(function ($item) { - return $this->transform($item); - }, $menu)); + $view->with('items', array_map(fn ($item) => $this->transform($item), $menu)); } public function transform(array $item): array @@ -66,9 +63,10 @@ class SideMenuComposer } if (Arr::has($item, 'children')) { - $item['children'] = array_map(function ($item) { - return $this->transform($item); - }, $item['children']); + $item['children'] = array_map( + fn ($item) => $this->transform($item), + $item['children'], + ); } $item['classes'] = $classes; @@ -82,9 +80,7 @@ class SideMenuComposer if (Arr::get($item, 'id') === 'plugin-configs') { $pluginConfigs = resolve(PluginManager::class) ->getEnabledPlugins() - ->filter(function ($plugin) { - return $plugin->hasConfig(); - }) + ->filter(fn (Plugin $plugin) => $plugin->hasConfig()) ->map(function ($plugin) { return [ 'title' => trans($plugin->title), @@ -95,7 +91,7 @@ class SideMenuComposer // Don't display this menu item when no plugin config is available if ($pluginConfigs->isNotEmpty()) { - $item['children'] = array_merge($item['children'], $pluginConfigs->values()->all()); + array_push($item['children'], ...$pluginConfigs->values()->all()); return $item; } diff --git a/app/Http/View/Composers/UserMenuComposer.php b/app/Http/View/Composers/UserMenuComposer.php index 94449c4f..5d8689cb 100644 --- a/app/Http/View/Composers/UserMenuComposer.php +++ b/app/Http/View/Composers/UserMenuComposer.php @@ -8,11 +8,9 @@ use Illuminate\View\View; class UserMenuComposer { - /** @var Request */ - protected $request; + protected Request $request; - /** @var Filter */ - protected $filter; + protected Filter $filter; public function __construct(Request $request, Filter $filter) { diff --git a/app/Http/View/Composers/UserPanelComposer.php b/app/Http/View/Composers/UserPanelComposer.php index 0e42d450..dd6a4bcc 100644 --- a/app/Http/View/Composers/UserPanelComposer.php +++ b/app/Http/View/Composers/UserPanelComposer.php @@ -9,11 +9,9 @@ use Illuminate\View\View; class UserPanelComposer { - /** @var Dispatcher */ - protected $dispatcher; + protected Dispatcher $dispatcher; - /** @var Filter */ - protected $filter; + protected Filter $filter; public function __construct(Dispatcher $dispatcher, Filter $filter) { diff --git a/app/Listeners/CleanUpFrontEndLocaleFiles.php b/app/Listeners/CleanUpFrontEndLocaleFiles.php index 27487875..a645b868 100644 --- a/app/Listeners/CleanUpFrontEndLocaleFiles.php +++ b/app/Listeners/CleanUpFrontEndLocaleFiles.php @@ -7,8 +7,7 @@ use Symfony\Component\Finder\SplFileInfo; class CleanUpFrontEndLocaleFiles { - /** @var Filesystem */ - protected $filesystem; + protected Filesystem $filesystem; public function __construct(Filesystem $filesystem) { diff --git a/app/Listeners/CopyPluginAssets.php b/app/Listeners/CopyPluginAssets.php index 51f60292..fb4e9e62 100644 --- a/app/Listeners/CopyPluginAssets.php +++ b/app/Listeners/CopyPluginAssets.php @@ -7,8 +7,7 @@ use Illuminate\Filesystem\Filesystem; class CopyPluginAssets { - /** @var Filesystem */ - protected $filesystem; + protected Filesystem $filesystem; public function __construct(Filesystem $filesystem) { diff --git a/app/Listeners/SetAppLocale.php b/app/Listeners/SetAppLocale.php index e4e4688e..9391390e 100644 --- a/app/Listeners/SetAppLocale.php +++ b/app/Listeners/SetAppLocale.php @@ -7,8 +7,7 @@ use Illuminate\Http\Request; class SetAppLocale { - /** @var Request */ - protected $request; + protected Request $request; public function __construct(Request $request) { diff --git a/app/Services/Hook.php b/app/Services/Hook.php index f033fc4e..64180af1 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -66,9 +66,7 @@ class Hook $urls = collect($urls); $pages = collect($pages); resolve(Filter::class)->add('head_links', function ($links) use ($urls, $pages) { - $matched = $pages->some(function ($page) { - return request()->is($page); - }); + $matched = $pages->some(fn ($page) => request()->is($page)); if ($matched) { $urls->each(function ($url) use (&$links) { $links[] = [ @@ -88,9 +86,7 @@ class Hook $urls = collect($urls); $pages = collect($pages); resolve(Filter::class)->add('scripts', function ($scripts) use ($urls, $pages) { - $matched = $pages->some(function ($page) { - return request()->is($page); - }); + $matched = $pages->some(fn ($page) => request()->is($page)); if ($matched) { $urls->each(function ($url) use (&$scripts) { $scripts[] = ['src' => $url, 'crossorigin' => 'anonymous']; diff --git a/app/Services/Option.php b/app/Services/Option.php index b0a9e5fa..79b3927d 100644 --- a/app/Services/Option.php +++ b/app/Services/Option.php @@ -21,9 +21,9 @@ class Option } try { - $this->items = DB::table('options')->get()->mapWithKeys(function ($item) { - return [$item->option_name => $item->option_value]; - }); + $this->items = DB::table('options') + ->get() + ->mapWithKeys(fn ($item) => [$item->option_name => $item->option_value]); } catch (QueryException $e) { $this->items = collect(); } diff --git a/app/Services/OptionForm.php b/app/Services/OptionForm.php index 809d191c..dc32f08a 100644 --- a/app/Services/OptionForm.php +++ b/app/Services/OptionForm.php @@ -329,7 +329,7 @@ class OptionForm $this->assignValues(); return view('forms.form') - ->with(array_merge(get_object_vars($this))) + ->with(get_object_vars($this)) ->render(); } diff --git a/app/Services/Plugin.php b/app/Services/Plugin.php index 568c6c76..36390003 100644 --- a/app/Services/Plugin.php +++ b/app/Services/Plugin.php @@ -15,19 +15,11 @@ class Plugin 'README.MD', ]; - /** - * The full path of this plugin. - * - * @var string - */ - protected $path; + /** The full path of this plugin. */ + protected string $path; - /** - * package.json of the package. - * - * @var array - */ - protected $manifest; + /** package.json of the package. */ + protected array $manifest; protected $enabled = false; @@ -61,9 +53,10 @@ class Plugin public function getReadme() { - return Arr::first(self::README_FILES, function ($filename) { - return file_exists($this->path.'/'.$filename); - }); + return Arr::first( + self::README_FILES, + fn ($filename) => file_exists($this->path.'/'.$filename) + ); } public function hasConfig(): bool diff --git a/app/Services/PluginManager.php b/app/Services/PluginManager.php index 54f7bf1c..0a68fe24 100644 --- a/app/Services/PluginManager.php +++ b/app/Services/PluginManager.php @@ -16,29 +16,21 @@ use Illuminate\Support\Str; class PluginManager { - /** @var bool */ - protected $booted = false; + protected bool $booted = false; - /** @var Application */ - protected $app; + protected Application $app; - /** @var Option */ - protected $option; + protected Option $option; - /** @var Dispatcher */ - protected $dispatcher; + protected Dispatcher $dispatcher; - /** @var Filesystem */ - protected $filesystem; + protected Filesystem $filesystem; - /** @var ClassLoader */ - protected $loader; + protected ClassLoader $loader; - /** @var Collection|null */ - protected $plugins; + protected ?Collection $plugins; - /** @var Collection */ - protected $enabled; + protected Collection $enabled; public function __construct( Application $app, @@ -56,28 +48,20 @@ class PluginManager public function all(): Collection { - if (filled($this->plugins)) { + if (isset($this->plugins)) { return $this->plugins; } $this->enabled = collect(json_decode($this->option->get('plugins_enabled', '[]'), true)) - ->reject(function ($item) { - return is_string($item); - }) - ->mapWithKeys(function ($item) { - return [$item['name'] => ['version' => $item['version']]]; - }); + ->reject(fn ($item) => is_string($item)) + ->mapWithKeys(fn ($item) => [$item['name'] => ['version' => $item['version']]]); $plugins = collect(); $versionChanged = []; $this->getPluginsDirs() - ->flatMap(function ($directory) { - return $this->filesystem->directories($directory); - }) + ->flatMap(fn ($dir) => $this->filesystem->directories($dir)) ->unique() - ->filter(function ($directory) { - return $this->filesystem->exists($directory.DIRECTORY_SEPARATOR.'package.json'); - }) + ->filter(fn ($dir) => $this->filesystem->exists($dir.DIRECTORY_SEPARATOR.'package.json')) ->each(function ($directory) use (&$plugins, &$versionChanged) { $manifest = json_decode( $this->filesystem->get($directory.DIRECTORY_SEPARATOR.'package.json'), @@ -126,18 +110,12 @@ class PluginManager return; } - $this->all()->each(function ($plugin) { - $this->loadViewsAndTranslations($plugin); - }); + $this->all()->each(fn ($plugin) => $this->loadViewsAndTranslations($plugin)); $enabled = $this->getEnabledPlugins(); - $enabled->each(function ($plugin) { - $this->registerPlugin($plugin); - }); + $enabled->each(fn ($plugin) => $this->registerPlugin($plugin)); $this->loader->register(); - $enabled->each(function ($plugin) { - $this->bootPlugin($plugin); - }); + $enabled->each(fn ($plugin) => $this->bootPlugin($plugin)); $this->registerLifecycleHooks(); $this->booted = true; @@ -324,9 +302,7 @@ class PluginManager public function getEnabledPlugins(): Collection { - return $this->all()->filter(function ($plugin) { - return $plugin->isEnabled(); - }); + return $this->all()->filter(fn ($plugin) => $plugin->isEnabled()); } /** @@ -334,9 +310,13 @@ class PluginManager */ protected function saveEnabled() { - $this->option->set('plugins_enabled', $this->enabled->map(function ($info, $name) { - return array_merge(compact('name'), $info); - })->values()->toJson()); + $this->option->set( + 'plugins_enabled', + $this->enabled + ->map(fn ($info, $name) => array_merge(['name' => $name], $info)) + ->values() + ->toJson() + ); } public function getUnsatisfied(Plugin $plugin) @@ -419,9 +399,7 @@ class PluginManager $config = config('plugins.directory'); if ($config) { return collect(preg_split('/,\s*/', $config)) - ->map(function ($directory) { - return realpath($directory) ?: $directory; - }); + ->map(fn ($directory) => realpath($directory) ?: $directory); } else { return collect([base_path('plugins')]); } diff --git a/app/Services/Translations/JavaScript.php b/app/Services/Translations/JavaScript.php index 01ecd92d..24958457 100644 --- a/app/Services/Translations/JavaScript.php +++ b/app/Services/Translations/JavaScript.php @@ -9,14 +9,11 @@ use Illuminate\Filesystem\Filesystem; class JavaScript { - /** @var Filesystem */ - protected $filesystem; + protected Filesystem $filesystem; - /** @var Repository */ - protected $cache; + protected Repository $cache; - /** @var PluginManager */ - protected $plugins; + protected PluginManager $plugins; protected $prefix = 'front-end-trans-'; @@ -34,16 +31,10 @@ class JavaScript { $plugins = $this->plugins->getEnabledPlugins(); $sourceFiles = $plugins - ->map(function (Plugin $plugin) use ($locale) { - return $plugin->getPath()."/lang/$locale/front-end.yml"; - }) - ->filter(function ($path) { - return $this->filesystem->exists($path); - }); + ->map(fn (Plugin $plugin) => $plugin->getPath()."/lang/$locale/front-end.yml") + ->filter(fn ($path) => $this->filesystem->exists($path)); $sourceFiles->push(resource_path("lang/$locale/front-end.yml")); - $sourceModified = $sourceFiles->max(function ($path) { - return $this->filesystem->lastModified($path); - }); + $sourceModified = $sourceFiles->max(fn ($path) => $this->filesystem->lastModified($path)); $compiled = public_path("lang/$locale.js"); $compiledModified = (int) $this->cache->get($this->prefix.$locale, 0); @@ -51,10 +42,7 @@ class JavaScript if ($sourceModified > $compiledModified || !$this->filesystem->exists($compiled)) { $translations = trans('front-end'); foreach ($plugins as $plugin) { - $translations = array_merge( - $translations, - [$plugin->name => trans($plugin->namespace.'::front-end')] - ); + $translations[$plugin->name] = trans($plugin->namespace.'::front-end'); } $content = 'blessing.i18n = '.json_encode($translations, JSON_UNESCAPED_UNICODE); diff --git a/app/Services/Translations/Yaml.php b/app/Services/Translations/Yaml.php index de2b0c11..457290e2 100644 --- a/app/Services/Translations/Yaml.php +++ b/app/Services/Translations/Yaml.php @@ -7,8 +7,7 @@ use Symfony\Component\Yaml\Yaml as YamlParser; class Yaml { - /** @var Repository */ - protected $cache; + protected Repository $cache; protected $prefix = 'yaml-trans-'; diff --git a/app/Services/Unzip.php b/app/Services/Unzip.php index fd7a6921..70324933 100644 --- a/app/Services/Unzip.php +++ b/app/Services/Unzip.php @@ -10,11 +10,9 @@ use ZipArchive; class Unzip { - /** @var Filesystem */ - protected $filesystem; + protected Filesystem $filesystem; - /** @var ZipArchive */ - protected $zipper; + protected ZipArchive $zipper; public function __construct(Filesystem $filesystem, ZipArchive $zipper) { diff --git a/app/Services/Webpack.php b/app/Services/Webpack.php index 4998ca03..db644769 100644 --- a/app/Services/Webpack.php +++ b/app/Services/Webpack.php @@ -11,12 +11,11 @@ use Illuminate\Support\Str; class Webpack { - protected $manifest = []; + protected array $manifest = []; - /** @var Option */ - protected $options; + protected Option $options; - protected $urlGenerator; + protected UrlGenerator $urlGenerator; public function __construct( Filesystem $filesystem, diff --git a/tests/ExceptionsTests/HandlerTest.php b/tests/ExceptionsTests/HandlerTest.php index 8a225a84..df7b3d7d 100644 --- a/tests/ExceptionsTests/HandlerTest.php +++ b/tests/ExceptionsTests/HandlerTest.php @@ -11,8 +11,8 @@ class HandlerTest extends TestCase $json = $this->get('/abc', ['Accept' => 'application/json'])->decodeResponseJson(); $this->assertIsString($json['message']); $this->assertTrue($json['exception']); - $this->assertTrue(collect($json['trace'])->every(function ($trace) { - return Str::startsWith($trace['file'], 'app') && is_int($trace['line']); - })); + $this->assertTrue(collect($json['trace'])->every( + fn ($trace) => Str::startsWith($trace['file'], 'app') && is_int($trace['line']) + )); } } diff --git a/tests/Fakes/Filter.php b/tests/Fakes/Filter.php index 5d2f92eb..9139fa0b 100644 --- a/tests/Fakes/Filter.php +++ b/tests/Fakes/Filter.php @@ -15,7 +15,7 @@ class Filter extends BaseFilter if (!Arr::has($this->applied, $hook)) { $this->applied[$hook] = []; } - $this->applied[$hook][] = array_merge([$init], $args); + $this->applied[$hook][] = [$init, ...$args]; return parent::apply($hook, $init, $args); } @@ -56,9 +56,7 @@ class Filter extends BaseFilter $result = Arr::first( $this->applied[$hook], - function ($arguments) use ($predicate) { - return call_user_func_array($predicate, $arguments); - } + fn ($arguments) => call_user_func_array($predicate, $arguments), ); Assert::assertNotNull( $result, diff --git a/tests/ServicesTest/OptionFormTest.php b/tests/ServicesTest/OptionFormTest.php index 4c2c9f66..862f04b1 100644 --- a/tests/ServicesTest/OptionFormTest.php +++ b/tests/ServicesTest/OptionFormTest.php @@ -242,9 +242,7 @@ class OptionFormTest extends TestCase public function testHandle() { $form = new OptionForm('test'); - $form->text('t')->format(function ($data) { - return "formatted $data"; - }); + $form->text('t')->format(fn ($data) => "formatted $data"); $request = request(); $request->setMethod('POST'); diff --git a/tests/ServicesTest/PluginManagerTest.php b/tests/ServicesTest/PluginManagerTest.php index 0e38c795..b4808059 100644 --- a/tests/ServicesTest/PluginManagerTest.php +++ b/tests/ServicesTest/PluginManagerTest.php @@ -375,9 +375,7 @@ class PluginManagerTest extends TestCase ->with('/mayaka/bootstrap.php') ->andReturn(function () { throw new \Exception(); - }, function () { - abort(500); - }); + }, fn () => abort(500)); }); app()->forgetInstance(PluginManager::class);