Skip to content

Commit

Permalink
MethodSignatureRuleTest - test conditional return types
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 23, 2022
1 parent 84f64f0 commit 0127e50
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php
Expand Up @@ -367,4 +367,16 @@ public function testMemcachePoolGet(): void
$this->analyse([__DIR__ . '/data/memcache-pool-get.php'], []);
}

public function testOverridenMethodWithConditionalReturnType(): void
{
$this->reportMaybes = true;
$this->reportStatic = true;
$this->analyse([__DIR__ . '/data/overriden-method-with-conditional-return-type.php'], [
[
'Return type (stdClass|string) of method OverridenMethodWithConditionalReturnType\Bar2::doFoo() should be covariant with return type (($p is int ? int : string)) of method OverridenMethodWithConditionalReturnType\Foo::doFoo()',
37,
],
]);
}

}
@@ -0,0 +1,42 @@
<?php

namespace OverridenMethodWithConditionalReturnType;

class Foo
{

/**
* @return ($p is int ? int : string)
*/
public function doFoo($p)
{

}

}

class Bar extends Foo
{

/**
* @return ($p is int ? int : string)
*/
public function doFoo($p)
{

}

}

class Bar2 extends Foo
{

/**
* @return ($p is int ? \stdClass : string)
*/
public function doFoo($p)
{

}

}

0 comments on commit 0127e50

Please sign in to comment.