From da0964b8cb1fef0d4d19b453315b82cf2433136f Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 29 Aug 2026 20:03:57 +0800 Subject: [PATCH] refactor: replace anonymous class with bound closure in `PropertiesTrait` --- system/Traits/PropertiesTrait.php | 15 +++++---------- utils/phpstan-baseline/loader.neon | 3 +-- .../missingType.iterableValue.neon | 8 -------- 3 files changed, 6 insertions(+), 20 deletions(-) delete mode 100644 utils/phpstan-baseline/missingType.iterableValue.neon diff --git a/system/Traits/PropertiesTrait.php b/system/Traits/PropertiesTrait.php index dd14e6c68d3a..26bb4bf322f4 100644 --- a/system/Traits/PropertiesTrait.php +++ b/system/Traits/PropertiesTrait.php @@ -13,6 +13,7 @@ namespace CodeIgniter\Traits; +use Closure; use ReflectionClass; use ReflectionProperty; @@ -48,17 +49,11 @@ final public function fill(array $params): self */ final public function getPublicProperties(): array { - $worker = new class () { - /** - * @return array - */ - public function getProperties(object $obj): array - { - return get_object_vars($obj); - } - }; + $fn = fn (): array => get_object_vars($this); + + $bound = Closure::bind($fn, $this, null); - return $worker->getProperties($this); + return $bound(); } /** diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 290d2f74e5a8..69bd50fab116 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 24 errors +# total 23 errors includes: - argument.type.neon @@ -8,6 +8,5 @@ includes: - function.resultUnused.neon - method.childParameterType.neon - method.childReturnType.neon - - missingType.iterableValue.neon - property.defaultValue.neon - property.phpDocType.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon deleted file mode 100644 index 43333c3fa6f6..000000000000 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Method class@anonymous/system/Traits/PropertiesTrait\.php\:51\:\:getProperties\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/View/Cells/Cell.php