Skip to content

Commit

Permalink
qa: Minor type inference improvements to ViewModel and ModelInterface
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Oct 17, 2023
1 parent 6188b66 commit b9bbb7f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 79 deletions.
72 changes: 1 addition & 71 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.14.0@b2942cefed8443002bd3f245c4cd0a54193716d8">
<file src="bin/templatemap_generator.php">
<MissingParamType>
<code>$templatePath</code>
</MissingParamType>
<MixedArgument>
<code>$file</code>
<code><![CDATA[$file->getExtension()]]></code>
<code>$templatePath</code>
</MixedArgument>
<MixedAssignment>
<code>$file</code>
<code>$files[]</code>
</MixedAssignment>
<MixedMethodCall>
<code>getExtension</code>
<code>getPathname</code>
</MixedMethodCall>
</file>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Helper/AbstractHtmlElement.php">
<MissingConstructor>
<code>$closingBracket</code>
Expand Down Expand Up @@ -1184,18 +1166,12 @@
<code>$viewModelHelper</code>
</MissingConstructor>
<MixedAssignment>
<code>$childModel</code>
<code><![CDATA[$this->viewModelHelper]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code>ViewModel</code>
<code>false|Model</code>
</MixedInferredReturnType>
<MixedMethodCall>
<code>captureTo</code>
</MixedMethodCall>
<MixedReturnStatement>
<code>$childModel</code>
<code><![CDATA[$this->viewModelHelper]]></code>
</MixedReturnStatement>
<PossiblyNullArgument>
Expand Down Expand Up @@ -1441,11 +1417,6 @@
<code>$captureTo</code>
</NonInvariantDocblockPropertyType>
</file>
<file src="src/Model/ModelInterface.php">
<MissingTemplateParam>
<code>IteratorAggregate</code>
</MissingTemplateParam>
</file>
<file src="src/Model/ViewModel.php">
<DocblockTypeContradiction>
<code>gettype($variables)</code>
Expand All @@ -1457,29 +1428,9 @@
<MixedArgumentTypeCoercion>
<code>$key</code>
</MixedArgumentTypeCoercion>
<MixedArrayAssignment>
<code>$children[]</code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$child</code>
<code>$children</code>
<code>$children[]</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType>
<code>array</code>
</MixedInferredReturnType>
<MixedMethodCall>
<code>captureTo</code>
<code>getChildrenByCaptureTo</code>
</MixedMethodCall>
<MixedOperand>
<code><![CDATA[$child->getChildrenByCaptureTo($capture)]]></code>
</MixedOperand>
<MixedReturnStatement>
<code>$children</code>
<code>$children</code>
</MixedReturnStatement>
<PossiblyInvalidArrayAccess>
<code>$variables[$name]</code>
</PossiblyInvalidArrayAccess>
Expand All @@ -1501,11 +1452,7 @@
<ImplementedParamTypeMismatch>
<code>$values</code>
</ImplementedParamTypeMismatch>
<MixedArgument>
<code>$child</code>
</MixedArgument>
<MixedAssignment>
<code>$child</code>
<code>$setting</code>
<code>$value</code>
</MixedAssignment>
Expand Down Expand Up @@ -1542,23 +1489,14 @@
<code>$jsonpCallback</code>
</MissingConstructor>
<MixedArgument>
<code>$child</code>
<code>$nameOrModel</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$child</code>
</MixedArgumentTypeCoercion>
<MixedArrayOffset>
<code>$values[$captureTo]</code>
</MixedArrayOffset>
<MixedAssignment>
<code>$captureTo</code>
<code>$child</code>
<code>$value</code>
</MixedAssignment>
<MixedMethodCall>
<code>captureTo</code>
</MixedMethodCall>
<PossiblyInvalidArgument>
<code>$childValues</code>
<code>$children</code>
Expand Down Expand Up @@ -1858,17 +1796,9 @@
<code>$request</code>
<code>$response</code>
</MissingConstructor>
<MixedArgument>
<code>$child</code>
</MixedArgument>
<MixedAssignment>
<code>$child</code>
<code>$oldResult</code>
</MixedAssignment>
<MixedMethodCall>
<code>setOption</code>
<code>terminate</code>
</MixedMethodCall>
<MixedOperand>
<code>$oldResult</code>
</MixedOperand>
Expand Down
4 changes: 3 additions & 1 deletion src/Model/ModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* to the model.
*
* Extends "IteratorAggregate"; should allow iterating over children.
*
* @extends IteratorAggregate<int, ModelInterface>
*/
interface ModelInterface extends Countable, IteratorAggregate
{
Expand Down Expand Up @@ -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<ModelInterface>
*/
public function getChildren();

Expand Down
2 changes: 1 addition & 1 deletion src/Model/RetrievableChildrenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface RetrievableChildrenInterface
*
* @param string $capture
* @param bool $recursive search recursive through children, default true
* @return array
* @return list<ModelInterface>
*/
public function getChildrenByCaptureTo($capture, $recursive = true);
}
12 changes: 6 additions & 6 deletions src/Model/ViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,8 +32,7 @@ class ViewModel implements ModelInterface, ClearableModelInterface, RetrievableC
/**
* Child models
*
* @var array
* @psalm-type list<ModelInterface>
* @var list<ModelInterface>
*/
protected $children = [];

Expand Down Expand Up @@ -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<ModelInterface>
*/
public function getChildren()
{
Expand Down Expand Up @@ -410,15 +410,15 @@ public function clearChildren()
*
* @param string $capture
* @param bool $recursive search recursive through children, default true
* @return array
* @return list<ModelInterface>
*/
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) {
Expand Down

0 comments on commit b9bbb7f

Please sign in to comment.