Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for issue 10622 #2961

Merged
merged 6 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading