From b9bbb7f7bc1b4f3de6d90f0e2d84063d1ab679a6 Mon Sep 17 00:00:00 2001 From: George Steel Date: Tue, 17 Oct 2023 23:11:35 +0100 Subject: [PATCH] qa: Minor type inference improvements to ViewModel and ModelInterface Signed-off-by: George Steel --- psalm-baseline.xml | 72 +--------------------- src/Model/ModelInterface.php | 4 +- src/Model/RetrievableChildrenInterface.php | 2 +- src/Model/ViewModel.php | 12 ++-- 4 files changed, 11 insertions(+), 79 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 799da0528..8e1e77db4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,23 +1,5 @@ - - - - $templatePath - - - $file - getExtension()]]> - $templatePath - - - $file - $files[] - - - getExtension - getPathname - - + $closingBracket @@ -1184,18 +1166,12 @@ $viewModelHelper - $childModel viewModelHelper]]> ViewModel - false|Model - - captureTo - - $childModel viewModelHelper]]> @@ -1441,11 +1417,6 @@ $captureTo - - - IteratorAggregate - - gettype($variables) @@ -1457,29 +1428,9 @@ $key - - $children[] - - $child - $children - $children[] $value - - array - - - captureTo - getChildrenByCaptureTo - - - getChildrenByCaptureTo($capture)]]> - - - $children - $children - $variables[$name] @@ -1501,11 +1452,7 @@ $values - - $child - - $child $setting $value @@ -1542,23 +1489,14 @@ $jsonpCallback - $child $nameOrModel $child - - $values[$captureTo] - - $captureTo - $child $value - - captureTo - $childValues $children @@ -1858,17 +1796,9 @@ $request $response - - $child - - $child $oldResult - - setOption - terminate - $oldResult diff --git a/src/Model/ModelInterface.php b/src/Model/ModelInterface.php index c9cb63e08..c1bcbafbf 100644 --- a/src/Model/ModelInterface.php +++ b/src/Model/ModelInterface.php @@ -16,6 +16,8 @@ * to the model. * * Extends "IteratorAggregate"; should allow iterating over children. + * + * @extends IteratorAggregate */ interface ModelInterface extends Countable, IteratorAggregate { @@ -105,7 +107,7 @@ public function addChild(ModelInterface $child, $captureTo = null, $append = fal * * Return specifies an array, but may be any iterable object. * - * @return array + * @return list */ public function getChildren(); diff --git a/src/Model/RetrievableChildrenInterface.php b/src/Model/RetrievableChildrenInterface.php index 88e5ad5e9..cf328c804 100644 --- a/src/Model/RetrievableChildrenInterface.php +++ b/src/Model/RetrievableChildrenInterface.php @@ -16,7 +16,7 @@ interface RetrievableChildrenInterface * * @param string $capture * @param bool $recursive search recursive through children, default true - * @return array + * @return list */ public function getChildrenByCaptureTo($capture, $recursive = true); } diff --git a/src/Model/ViewModel.php b/src/Model/ViewModel.php index a33ca643a..2067b2cc7 100644 --- a/src/Model/ViewModel.php +++ b/src/Model/ViewModel.php @@ -13,6 +13,7 @@ use Traversable; use function array_key_exists; +use function array_merge; use function count; use function gettype; use function is_array; @@ -31,8 +32,7 @@ class ViewModel implements ModelInterface, ClearableModelInterface, RetrievableC /** * Child models * - * @var array - * @psalm-type list + * @var list */ protected $children = []; @@ -377,7 +377,7 @@ public function addChild(ModelInterface $child, $captureTo = null, $append = nul * * Return specifies an array, but may be any iterable object. * - * @return array + * @return list */ public function getChildren() { @@ -410,15 +410,15 @@ public function clearChildren() * * @param string $capture * @param bool $recursive search recursive through children, default true - * @return array + * @return list */ public function getChildrenByCaptureTo($capture, $recursive = true) { $children = []; foreach ($this->children as $child) { - if ($recursive === true) { - $children += $child->getChildrenByCaptureTo($capture); + if ($recursive === true && $child instanceof RetrievableChildrenInterface) { + $children = array_merge($children, $child->getChildrenByCaptureTo($capture)); } if ($child->captureTo() === $capture) {