From c3434629a6abb09b318b32378f974303cc33156a Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 7 Jul 2022 17:26:43 +0300 Subject: [PATCH] refactor(core): code updates and improvements - phpstan level 4 --- phpstan.neon | 2 +- .../core/Cache/Drivers/Phparray/Driver.php | 2 +- .../Commands/Tokens/TokensVerifyHashCommand.php | 2 +- src/flextype/core/Entries/Entries.php | 3 --- .../core/Parsers/Shortcodes/StringsShortcode.php | 14 +++----------- .../core/Parsers/Shortcodes/VarShortcode.php | 4 ++-- src/flextype/helpers/finder.php | 2 +- 7 files changed, 9 insertions(+), 20 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 1b1ea08e..b734aefe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 4 reportUnmatchedIgnoredErrors: false bootstrapFiles: - src/flextype/defines.php diff --git a/src/flextype/core/Cache/Drivers/Phparray/Driver.php b/src/flextype/core/Cache/Drivers/Phparray/Driver.php index 5441d211..dad98d13 100644 --- a/src/flextype/core/Cache/Drivers/Phparray/Driver.php +++ b/src/flextype/core/Cache/Drivers/Phparray/Driver.php @@ -47,7 +47,7 @@ class Driver implements AggregatablePoolInterface { use IOHelperTrait; - private static string $ext = 'php'; + protected static string $ext = 'php'; /** * @throws PhpfastcacheIOException diff --git a/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php index a8d6ac65..ae6d389d 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php @@ -38,7 +38,7 @@ class TokensVerifyHashCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { - dd($input->getArgument('token-hash')); + if (verifyTokenHash($input->getArgument('token'), $input->getArgument('token-hash'))) { $output->write( renderToString( diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index 9f536bf9..74264e20 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -566,9 +566,6 @@ class Entries // Return entries array return collection($this->registry()->get('methods.fetch.result')); } - - // Return entries array - return collection($this->registry()->get('methods.fetch.result')); } /** diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index 2efdac89..f489a7b4 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -44,22 +44,14 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa $vars = $value !== null ? strings($value)->contains($varsDelimeter) ? explode($varsDelimeter, $value) : [$value] : []; // Parse shortcodes for each var. - $vars = array_map(static fn ($v) => parsers()->shortcodes()->parse(is_string($v) ? $v : ''), $vars); + $vars = array_map(static fn ($v) => parsers()->shortcodes()->parse((string) $v), $vars); if ($key === 'append') { - if (is_iterable($vars)) { - $content = strings($content)->{'append'}(...$vars)->toString(); - } else { - $content = strings($content)->{'append'}($vars[0])->toString(); - } + $content = strings($content)->{'append'}(...$vars)->toString(); } if ($key === 'prepend') { - if (is_iterable($vars)) { - $content = strings($content)->{'prepend'}(...$vars)->toString(); - } else { - $content = strings($content)->{'prepend'}($vars[0])->toString(); - } + $content = strings($content)->{'prepend'}(...$vars)->toString(); } if ($key === 'after') { diff --git a/src/flextype/core/Parsers/Shortcodes/VarShortcode.php b/src/flextype/core/Parsers/Shortcodes/VarShortcode.php index 435e45b1..7726ffde 100644 --- a/src/flextype/core/Parsers/Shortcodes/VarShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/VarShortcode.php @@ -31,8 +31,8 @@ parsers()->shortcodes()->addHandler('var', static function (ShortcodeInterface $ if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.var.enabled')) { return ''; } - - $params = $s->getParameters() ?? ''; + + $params = $s->getParameters(); if (isset($params['set'])) { if (isset($params['value'])) { diff --git a/src/flextype/helpers/finder.php b/src/flextype/helpers/finder.php index d784946d..7a96d864 100644 --- a/src/flextype/helpers/finder.php +++ b/src/flextype/helpers/finder.php @@ -23,7 +23,7 @@ if (! function_exists('find')) { { $find = filesystem()->find()->in($path); - isset($options['depth']) and $find->depth($options['depth']) or $find->depth(1); + isset($options['depth']) ? $find->depth($options['depth']) : $find->depth(1); isset($options['date']) and $find->date($options['date']); isset($options['size']) and $find->size($options['size']); isset($options['exclude']) and $find->exclude($options['exclude']);