From ab30253a75b4e0215c7b665320181b50075f5172 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 13 Sep 2023 23:35:01 +0700 Subject: [PATCH 1/8] [PHPStan] Add @var string[] on array of string with enable StringifyStrNeedlesRector --- rector.php | 2 -- .../ControllerMethodReader.php | 3 +++ system/Email/Email.php | 4 ++-- system/Router/RouteCollection.php | 24 ++++++++++++++----- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/rector.php b/rector.php index 580b8b38295c..0cbfa41114b1 100644 --- a/rector.php +++ b/rector.php @@ -37,7 +37,6 @@ use Rector\Php70\Rector\FuncCall\RandomFunctionRector; use Rector\Php71\Rector\FuncCall\CountOnNullRector; use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; -use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; @@ -80,7 +79,6 @@ __DIR__ . '/tests/system/Filters/fixtures', __DIR__ . '/tests/_support', JsonThrowOnErrorRector::class, - StringifyStrNeedlesRector::class, YieldDataProviderRector::class, RemoveUnusedPrivateMethodRector::class => [ diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php index 74b268befe7d..4947fbc60410 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php @@ -26,6 +26,9 @@ final class ControllerMethodReader */ private string $namespace; + /** + * @var string[] + */ private array $httpMethods; /** diff --git a/system/Email/Email.php b/system/Email/Email.php index c5b043922938..0ee5540d95f9 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -352,7 +352,7 @@ class Email * Character sets valid for 7-bit encoding, * excluding language suffix. * - * @var array + * @var string[] */ protected $baseCharsets = [ 'us-ascii', @@ -862,7 +862,7 @@ protected function getEncoding() } foreach ($this->baseCharsets as $charset) { - if (strpos($this->charset, $charset) === 0) { + if (strpos($this->charset, (string) $charset) === 0) { $this->encoding = '7bit'; break; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 63b7397dbc4c..25305e3b70e4 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1293,9 +1293,15 @@ protected function fillRouteParams(string $from, ?array $params = null): string return '/' . ltrim($from, '/'); } - // Build our resulting string, inserting the $params in - // the appropriate places. - foreach ($matches[0] as $index => $pattern) { + /** + * Build our resulting string, inserting the $params in + * the appropriate places. + * + * @var string[] $patterns + */ + $patterns = $matches[0]; + + foreach ($patterns as $index => $pattern) { if (! preg_match('#^' . $pattern . '$#u', $params[$index])) { throw RouterException::forInvalidParameterType(); } @@ -1338,9 +1344,15 @@ protected function buildReverseRoute(string $from, array $params): string $locale = $params[$placeholderCount]; } - // Build our resulting string, inserting the $params in - // the appropriate places. - foreach ($matches[0] as $index => $placeholder) { + /** + * Build our resulting string, inserting the $params in + * the appropriate places. + * + * @var string[] $placeholders + */ + $placeholders = $matches[0]; + + foreach ($placeholders as $index => $placeholder) { if (! isset($params[$index])) { throw new InvalidArgumentException( 'Missing argument for "' . $placeholder . '" in route "' . $from . '".' From c1d21a5f693706c580027653317348775bda6bd1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 13 Sep 2023 23:37:29 +0700 Subject: [PATCH 2/8] remove unused cast --- system/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 0ee5540d95f9..844033df4c26 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -862,7 +862,7 @@ protected function getEncoding() } foreach ($this->baseCharsets as $charset) { - if (strpos($this->charset, (string) $charset) === 0) { + if (strpos($this->charset, $charset) === 0) { $this->encoding = '7bit'; break; From 4549a7c96cbaa5a47f764114b9f4ae300491614c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 12:30:26 +0700 Subject: [PATCH 3/8] Update system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php Co-authored-by: kenjis --- .../Routes/AutoRouterImproved/ControllerMethodReader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php index 4947fbc60410..a5383df6cde5 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php @@ -27,7 +27,8 @@ final class ControllerMethodReader private string $namespace; /** - * @var string[] + * @var arrray + * @phpstan-var list */ private array $httpMethods; From 02bcc0476367b1f8dfc0768e2c6c3a8921e8930c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 12:30:32 +0700 Subject: [PATCH 4/8] Update system/Email/Email.php Co-authored-by: kenjis --- system/Email/Email.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 844033df4c26..eb92a6b9ef7a 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -352,7 +352,8 @@ class Email * Character sets valid for 7-bit encoding, * excluding language suffix. * - * @var string[] + * @var arrray + * @phpstan-var list */ protected $baseCharsets = [ 'us-ascii', From aa5dd51e8c8f679c0e718b97c55fd5d6460d6195 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 12:30:40 +0700 Subject: [PATCH 5/8] Update system/Router/RouteCollection.php Co-authored-by: kenjis --- system/Router/RouteCollection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 25305e3b70e4..64d038fc4d04 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1297,7 +1297,8 @@ protected function fillRouteParams(string $from, ?array $params = null): string * Build our resulting string, inserting the $params in * the appropriate places. * - * @var string[] $patterns + * @var arrray $patterns + * @phpstan-var list $patterns */ $patterns = $matches[0]; From 8d9afe0ae610e3c48dfde8a654d7fce016f834da Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 12:30:49 +0700 Subject: [PATCH 6/8] Update system/Router/RouteCollection.php Co-authored-by: kenjis --- system/Router/RouteCollection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 64d038fc4d04..31961fb61328 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1349,7 +1349,8 @@ protected function buildReverseRoute(string $from, array $params): string * Build our resulting string, inserting the $params in * the appropriate places. * - * @var string[] $placeholders + * @var arrray $patterns + * @phpstan-var list $patterns */ $placeholders = $matches[0]; From 2ba4576249db868b92f601b7acb21c6ff762727f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 12:47:09 +0700 Subject: [PATCH 7/8] Update system/Router/RouteCollection.php Co-authored-by: Pooya Parsa --- system/Router/RouteCollection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 31961fb61328..9e2cc43a1eeb 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1349,8 +1349,8 @@ protected function buildReverseRoute(string $from, array $params): string * Build our resulting string, inserting the $params in * the appropriate places. * - * @var arrray $patterns - * @phpstan-var list $patterns + * @var arrray $placeholders + * @phpstan-var list $placeholders */ $placeholders = $matches[0]; From 29e3186f6c9fab8e5ae35ddf1c6471c94530d1d7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 14 Sep 2023 13:21:37 +0700 Subject: [PATCH 8/8] typo fix: arrray to array --- .../Routes/AutoRouterImproved/ControllerMethodReader.php | 2 +- system/Email/Email.php | 2 +- system/Router/RouteCollection.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php index a5383df6cde5..a8b6912d4bf7 100644 --- a/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php +++ b/system/Commands/Utilities/Routes/AutoRouterImproved/ControllerMethodReader.php @@ -27,7 +27,7 @@ final class ControllerMethodReader private string $namespace; /** - * @var arrray + * @var array * @phpstan-var list */ private array $httpMethods; diff --git a/system/Email/Email.php b/system/Email/Email.php index eb92a6b9ef7a..a6ad2d993204 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -352,7 +352,7 @@ class Email * Character sets valid for 7-bit encoding, * excluding language suffix. * - * @var arrray + * @var array * @phpstan-var list */ protected $baseCharsets = [ diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 9e2cc43a1eeb..4a052699196c 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1297,7 +1297,7 @@ protected function fillRouteParams(string $from, ?array $params = null): string * Build our resulting string, inserting the $params in * the appropriate places. * - * @var arrray $patterns + * @var array $patterns * @phpstan-var list $patterns */ $patterns = $matches[0]; @@ -1349,7 +1349,7 @@ protected function buildReverseRoute(string $from, array $params): string * Build our resulting string, inserting the $params in * the appropriate places. * - * @var arrray $placeholders + * @var array $placeholders * @phpstan-var list $placeholders */ $placeholders = $matches[0];