Skip to content

Instantly share code, notes, and snippets.

@lunetics
Last active June 22, 2020 10:55
Show Gist options
  • Save lunetics/d8adce5dae1cb9e076270f78b3e2eeb2 to your computer and use it in GitHub Desktop.
Save lunetics/d8adce5dae1cb9e076270f78b3e2eeb2 to your computer and use it in GitHub Desktop.
<?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