Skip to content

Commit 2cc943c

Browse files
authored
Merge pull request #30 from gsteel/minor-type-docs-improvement
Improve type inference for DefaultParamsTrait
2 parents c037173 + 714416b commit 2cc943c

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,4 @@
88
<code>render</code>
99
</PossiblyUnusedMethod>
1010
</file>
11-
<file src="test/ArrayParametersTraitTest.php">
12-
<PossiblyUnusedMethod>
13-
<code>nonNullScalarParameters</code>
14-
</PossiblyUnusedMethod>
15-
</file>
16-
<file src="test/ExceptionTest.php">
17-
<PossiblyUnusedMethod>
18-
<code>exception</code>
19-
</PossiblyUnusedMethod>
20-
</file>
21-
<file src="test/TemplatePathAssertionsTrait.php">
22-
<PossiblyUnusedMethod>
23-
<code>assertEqualTemplatePath</code>
24-
</PossiblyUnusedMethod>
25-
</file>
26-
<file src="test/TestAsset/ViewModel.php">
27-
<PossiblyUnusedMethod>
28-
<code>getVariables</code>
29-
</PossiblyUnusedMethod>
30-
</file>
3111
</files>

psalm.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
</projectFiles>
1919

2020
<issueHandlers>
21-
<InternalMethod>
21+
<UnusedClass>
2222
<errorLevel type="suppress">
23-
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::method"/>
23+
<directory name="test/StaticAnalysis" />
2424
</errorLevel>
25+
</UnusedClass>
26+
<PossiblyUnusedMethod>
2527
<errorLevel type="suppress">
26-
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::willReturn"/>
28+
<directory name="test" />
2729
</errorLevel>
28-
<errorLevel type="suppress">
29-
<referencedMethod name="PHPUnit\Framework\MockObject\Builder\InvocationMocker::with"/>
30-
</errorLevel>
31-
</InternalMethod>
30+
</PossiblyUnusedMethod>
3231
</issueHandlers>
3332

3433
<plugins>

src/DefaultParamsTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function addDefaultParam(string $templateName, string $param, mixed $valu
5252

5353
/**
5454
* Returns merged global, template-specific and given params
55+
*
56+
* @template TKey of array-key
57+
* @param array<TKey, mixed> $params
58+
* @return array<TKey, mixed>
5559
*/
5660
private function mergeParams(string $template, array $params): array
5761
{

test/DefaultParamsTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testMergingParamsWithDefaultParamArray(): void
6868
3 => ['id' => 3],
6969
4 => ['id' => 4],
7070
],
71-
])
71+
]),
7272
);
7373
$params = $this->defaultParams->mergeParameters('template', $params);
7474

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MezzioTest\Template\StaticAnalysis;
6+
7+
use Mezzio\Template\DefaultParamsTrait;
8+
9+
final class DefaultParameters
10+
{
11+
use DefaultParamsTrait;
12+
13+
/**
14+
* @param array<string, mixed> $params
15+
* @return array<string, mixed>
16+
*/
17+
public function mergePreservesKeyType(array $params): array
18+
{
19+
return $this->mergeParams('whatever', $params);
20+
}
21+
}

0 commit comments

Comments
 (0)