Skip to content

Commit

Permalink
Add more tests for issue #10622
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Mar 22, 2024
1 parent bfa530a commit 0f2366b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,9 @@ public function testBug10622(): void
$this->analyse([__DIR__ . '/data/bug-10622.php'], []);
}

public function testBug10622B(): void
{
$this->analyse([__DIR__ . '/data/bug-10622b.php'], []);
}

}
71 changes: 71 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-10622b.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Bug10622B;

/**
* @template T of array<mixed>
*/
class FooBoxedArray
{
/** @var T */
private $value;

/**
* @param T $value
*/
public function __construct(array $value)
{
$this->value = $value;
}

/**
* @return T
*/
public function get(): array
{
return $this->value;
}
}

/**
* @template TKey of object|array<mixed>
* @template TValue of object|array<mixed>
*/
class FooMap
{
/**
* @var array<int, array{
* \WeakReference<(TKey is object ? TKey : FooBoxedArray<TKey>)>,
* \WeakReference<(TValue is object ? TValue : FooBoxedArray<TValue>)>
* }>
*/
protected $weakKvByIndex = [];

/**
* @template T of TKey|TValue
*
* @param T $value
*
* @return (T is object ? T : FooBoxedArray<T>)
*/
protected function boxValue($value): object
{
return is_array($value)
? new FooBoxedArray($value)
: $value;
}

/**
* @template T of TKey|TValue
*
* @param (T is object ? T : FooBoxedArray<T>) $value
*
* @return T
*/
protected function unboxValue(object $value)
{
return $value instanceof FooBoxedArray
? $value->get()
: $value;
}
}

0 comments on commit 0f2366b

Please sign in to comment.