From 45cba18f47d918809955585457954b9b5ec8a980 Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 7 Jul 2022 16:09:06 +0300 Subject: [PATCH] refactor(core): code updates and improvements - phpstan level 2 --- phpstan.neon | 2 +- src/flextype/core/Actions.php | 4 ++-- src/flextype/core/Entries/Entries.php | 8 ++++---- .../core/Entries/Expressions/EntriesExpression.php | 10 +++++----- src/flextype/core/I18n.php | 6 +++--- src/flextype/core/Middlewares/CsrfMiddleware.php | 2 +- src/flextype/helpers/image.php | 1 - src/flextype/helpers/tokens.php | 3 +-- src/flextype/helpers/upload.php | 2 +- 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 5cb3cd09..d5581f7e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 1 + level: 2 reportUnmatchedIgnoredErrors: false bootstrapFiles: - src/flextype/defines.php diff --git a/src/flextype/core/Actions.php b/src/flextype/core/Actions.php index e574e789..08469fb0 100644 --- a/src/flextype/core/Actions.php +++ b/src/flextype/core/Actions.php @@ -23,12 +23,12 @@ class Actions extends Collection /** * Actions instance */ - private static ?Actions $instance = null; + protected static Actions|null $instance = null; /** * Actions registry storage */ - private static ?Collection $registry = null; + protected static Collection|null $registry = null; /** * Gets the instance via lazy initialization (created on first usage) diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index 1f7ee3fd..9a65818c 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -777,7 +777,7 @@ class Entries * @param string $id Unique identifier of the entry. * @param string $newID New Unique identifier of the entry. * - * @return boolы True on success, false on failure. + * @return bool True on success, false on failure. * * @access public */ @@ -987,7 +987,7 @@ class Entries /** * Set Entries registry. * - * @return void + * @return self * * @access public */ @@ -1001,7 +1001,7 @@ class Entries /** * Set Entries options. * - * @return void + * @return self * * @access public */ @@ -1015,7 +1015,7 @@ class Entries /** * Get Entries options. * - * @return array Returns entries options. + * @return Collection Returns entries options. * * @access public */ diff --git a/src/flextype/core/Entries/Expressions/EntriesExpression.php b/src/flextype/core/Entries/Expressions/EntriesExpression.php index 2b858aca..f8fa4f51 100644 --- a/src/flextype/core/Entries/Expressions/EntriesExpression.php +++ b/src/flextype/core/Entries/Expressions/EntriesExpression.php @@ -16,7 +16,7 @@ declare(strict_types=1); namespace Flextype\Entries\Expressions; -use Glowy\Arrays\Arrays as Collection; +use Glowy\Arrays\Arrays; use Glowy\Macroable\Macroable; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; @@ -41,11 +41,11 @@ class EntriesTwigExpressionsMethods * @param string $id Unique identifier of the entry. * @param array $options Options array. * - * @return self Returns instance of The Arrays class. + * @return \Glowy\Arrays\Arrays Returns instance of The Arrays class. * * @access public */ - public function fetch(string $id, array $options = []): Collection + public function fetch(string $id, array $options = []): \Glowy\Arrays\Arrays { return entries()->fetch($id, $options); } @@ -53,11 +53,11 @@ class EntriesTwigExpressionsMethods /** * Get Entries Registry. * - * @return Collection Returns entries registry. + * @return \Glowy\Arrays\Arrays Returns entries registry. * * @access public */ - public function registry(): Collection + public function registry(): \Glowy\Arrays\Arrays { return entries()->registry(); } diff --git a/src/flextype/core/I18n.php b/src/flextype/core/I18n.php index 481cb8f5..81daa69b 100644 --- a/src/flextype/core/I18n.php +++ b/src/flextype/core/I18n.php @@ -41,10 +41,10 @@ class I18n * New translation keys for `en_US` locale * I18n::add(['auth_login' => 'Login', 'auth_password' => 'Password'], 'en_US'); * - * @param string $translates Translation keys and values to add - * @param string $locale Locale + * @param array $translates Translation keys and values to add + * @param string|null $locale Locale */ - public static function add(array $translates, ?string $locale = null): void + public static function add(array $translates, string|null $locale = null): void { $locale ??= self::$locale; diff --git a/src/flextype/core/Middlewares/CsrfMiddleware.php b/src/flextype/core/Middlewares/CsrfMiddleware.php index 49952b9f..b318e993 100644 --- a/src/flextype/core/Middlewares/CsrfMiddleware.php +++ b/src/flextype/core/Middlewares/CsrfMiddleware.php @@ -27,7 +27,7 @@ class CsrfMiddleware /** * Invoke * - * @param ServerRequest $request PSR-7 request + * @param Request $request PSR-7 request * @param RequestHandler $handler PSR-15 request handler */ public function __invoke(Request $request, RequestHandler $handler): Response diff --git a/src/flextype/helpers/image.php b/src/flextype/helpers/image.php index 53820bfe..c4b945e9 100644 --- a/src/flextype/helpers/image.php +++ b/src/flextype/helpers/image.php @@ -17,7 +17,6 @@ if (! function_exists('imageFile')) { * Create a new image instance for image file. * * @param string $file Image file. - * @param array $options Options array. */ function imageFile(string $file): Image { diff --git a/src/flextype/helpers/tokens.php b/src/flextype/helpers/tokens.php index 26611c49..b05962e3 100644 --- a/src/flextype/helpers/tokens.php +++ b/src/flextype/helpers/tokens.php @@ -18,7 +18,7 @@ if (! function_exists('generateToken')) { * * @param int $length Token string length. * - * @return strings Token string. + * @return string Token string. */ function generateToken(int $length = 16): string { @@ -30,7 +30,6 @@ if (! function_exists('generateTokenHash')) { /** * Generate token hash. * - * @return strings Token string. * @return string Token string hashed. */ function generateTokenHash(string $token): string diff --git a/src/flextype/helpers/upload.php b/src/flextype/helpers/upload.php index 25c725de..c8e98182 100644 --- a/src/flextype/helpers/upload.php +++ b/src/flextype/helpers/upload.php @@ -55,7 +55,7 @@ if (! function_exists('upload')) { $result->confirm(); // If upload file is image, do image file processing - if ($result->name) { + if (property_exists($result, 'name')) { $mediaFile = $uploadFolder . '/' . $result->name; if (getimagesize($mediaFile)) {