mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Merge pull request #2950 from gnutix/GetClassOnNullRector/add_broken_test_in_trait
[GetClassOnNullRector] Add failing test in trait.
This commit is contained in:
commit
d3bf2c0364
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Php72\Tests\Rector\FuncCall\GetClassOnNullRector\Fixture;
|
||||
|
||||
trait SomeTrait
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
private function someMethodInTrait(?object $objectInTrait)
|
||||
{
|
||||
if (null === $objectInTrait) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return get_class($objectInTrait);
|
||||
}
|
||||
}
|
||||
|
||||
final class SomeClassUsingTheTrait
|
||||
{
|
||||
use SomeTrait;
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = 42;
|
||||
|
||||
$fromClass = $this->someMethodInClass($object);
|
||||
$fromTrait = $this->someMethodInTrait($object);
|
||||
}
|
||||
|
||||
public function someMethodInClass(?object $objectInClass)
|
||||
{
|
||||
if (null === $objectInClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return get_class($objectInClass);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user