Last active
June 22, 2020 10:55
-
-
Save lunetics/d8adce5dae1cb9e076270f78b3e2eeb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
class Bar | |
{ | |
public function getStuff() : int | |
{ | |
return 1; | |
} | |
} | |
class BarList | |
{ | |
protected $list; | |
public function __construct() | |
{ | |
$this->list = [new \Bar()]; | |
} | |
public function getList() | |
{ | |
return $this->list; | |
} | |
} | |
class Foo | |
{ | |
public static function doStuff(BarList $list) : array | |
{ | |
/** @var Bar $bar */ | |
$bar = $list->getList()[0]; | |
$bar->invalidMethod(); | |
$list->getList()[0]->invalidMethod(); | |
foreach($list->getList() as $fooBar) { | |
$fooBar->invalidMethod(); | |
$fooBar->getStuff(); | |
} | |
return array_values( | |
array_map( | |
function (Bar $bar) : void { | |
$bar->invalidMethod(); | |
}, | |
$list->getList() | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment