Skip to content

Commit 1e77aed

Browse files
committed
Countable stub for bleedingEdge
1 parent 9d81ab9 commit 1e77aed

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

conf/bleedingEdge.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ parameters:
22
featureToggles:
33
bleedingEdge: true
44
skipCheckGenericClasses: []
5+
stubFiles:
6+
- ../stubs/bleedingEdge/Countable.stub

stubs/bleedingEdge/Countable.stub

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
interface Countable
4+
{
5+
/**
6+
* @return 0|positive-int
7+
*/
8+
public function count(): int;
9+
}

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,9 @@ public function dataFileAsserts(): iterable
712712
}
713713

714714
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6672.php');
715+
716+
require_once __DIR__ . '/data/countable.php';
717+
yield from $this->gatherAssertTypes(__DIR__ . '/data/countable.php');
715718
}
716719

717720
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace CountablePhpDocInheritance;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo implements \Countable {
8+
public function count() : int {
9+
return 0;
10+
}
11+
12+
static public function doFoo() {
13+
$foo = new Foo();
14+
assertType('int<0, max>', $foo->count());
15+
}
16+
}
17+

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,15 @@ public function testBug3997(): void
210210
$this->reportStatic = true;
211211
$this->analyse([__DIR__ . '/data/bug-3997.php'], [
212212
[
213-
'Return type (string) of method Bug3997\Ipsum::count() should be compatible with return type (int) of method Countable::count()',
213+
'Return type (int) of method Bug3997\Baz::count() should be covariant with return type (int<0, max>) of method Countable::count()',
214+
PHP_VERSION_ID >= 80000 || self::$useStaticReflectionProvider ? 35 : 36,
215+
],
216+
[
217+
'Return type (int) of method Bug3997\Lorem::count() should be covariant with return type (int<0, max>) of method Countable::count()',
218+
PHP_VERSION_ID >= 80000 || self::$useStaticReflectionProvider ? 49 : 50,
219+
],
220+
[
221+
'Return type (string) of method Bug3997\Ipsum::count() should be compatible with return type (int<0, max>) of method Countable::count()',
214222
PHP_VERSION_ID >= 80000 || self::$useStaticReflectionProvider ? 63 : 64,
215223
],
216224
]);

tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,11 @@ public function testBug3997(): void
377377
{
378378
$this->analyse([__DIR__ . '/data/bug-3997.php'], [
379379
[
380-
'Method Bug3997\Foo::count() should return int but returns string.',
380+
"Method Bug3997\Foo::count() should return int<0, max> but returns 'foo'.",
381381
13,
382382
],
383383
[
384-
'Method Bug3997\Bar::count() should return int but returns string.',
384+
"Method Bug3997\Bar::count() should return int<0, max> but returns 'foo'.",
385385
24,
386386
],
387387
[

0 commit comments

Comments
 (0)