Skip to content

Commit

Permalink
Merge pull request #30 from gsteel/minor-type-docs-improvement
Browse files Browse the repository at this point in the history
Improve type inference for DefaultParamsTrait
  • Loading branch information
gsteel authored Jan 8, 2024
2 parents c037173 + 714416b commit 2cc943c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
20 changes: 0 additions & 20 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,4 @@
<code>render</code>
</PossiblyUnusedMethod>
</file>
<file src="test/ArrayParametersTraitTest.php">
<PossiblyUnusedMethod>
<code>nonNullScalarParameters</code>
</PossiblyUnusedMethod>
</file>
<file src="test/ExceptionTest.php">
<PossiblyUnusedMethod>
<code>exception</code>
</PossiblyUnusedMethod>
</file>
<file src="test/TemplatePathAssertionsTrait.php">
<PossiblyUnusedMethod>
<code>assertEqualTemplatePath</code>
</PossiblyUnusedMethod>
</file>
<file src="test/TestAsset/ViewModel.php">
<PossiblyUnusedMethod>
<code>getVariables</code>
</PossiblyUnusedMethod>
</file>
</files>
13 changes: 6 additions & 7 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
</projectFiles>

<issueHandlers>
<InternalMethod>
<UnusedClass>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
<directory name="test/StaticAnalysis" />
</errorLevel>
</UnusedClass>
<PossiblyUnusedMethod>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
<directory name="test" />
</errorLevel>
<errorLevel type="suppress">
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
</errorLevel>
</InternalMethod>
</PossiblyUnusedMethod>
</issueHandlers>

<plugins>
Expand Down
4 changes: 4 additions & 0 deletions src/DefaultParamsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function addDefaultParam(string $templateName, string $param, mixed $valu

/**
* Returns merged global, template-specific and given params
*
* @template TKey of array-key
* @param array<TKey, mixed> $params
* @return array<TKey, mixed>
*/
private function mergeParams(string $template, array $params): array
{
Expand Down
2 changes: 1 addition & 1 deletion test/DefaultParamsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testMergingParamsWithDefaultParamArray(): void
3 => ['id' => 3],
4 => ['id' => 4],
],
])
]),
);
$params = $this->defaultParams->mergeParameters('template', $params);

Expand Down
21 changes: 21 additions & 0 deletions test/StaticAnalysis/DefaultParameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace MezzioTest\Template\StaticAnalysis;

use Mezzio\Template\DefaultParamsTrait;

final class DefaultParameters
{
use DefaultParamsTrait;

/**
* @param array<string, mixed> $params
* @return array<string, mixed>
*/
public function mergePreservesKeyType(array $params): array
{
return $this->mergeParams('whatever', $params);
}
}

0 comments on commit 2cc943c

Please sign in to comment.