class Resolver
{
private Foo $foo;
public function __construct(Foo $foo)
{
$this->foo = $foo;
}
public function resolve(string $status): void
{
if ($this->getResolvingStrategy()->needsCreate($status)) {
$this->foo->create();
} elseif ($this->getResolvingStrategy()->needsCancel($status)) {
$this->foo->cancel();
} elseif ($this->getResolvingStrategy()->needsCommit($status)) {
$this->foo->commit();
}
}
private function getResolvingStrategy(): ResolvingStrategy
{
if ($this->foo instanceof Bar) {
return new BarResolvingStrategy();
}
if ($this->foo instanceof Baz) {
return new BazResolvingStrategy();
}
throw new Exception();
}
}
class BarResolvingStrategy implements ResolvingStrategy
{
public function needsCreate(string $status): bool
{
return $status === 'A';
}
public function needsCancel(string $status): bool
{
return $status === 'B';
}
public function needsCommit(string $status): bool
{
return $status === 'C';
}
}
class BazResolvingStrategy implements ResolvingStrategy
{
public function needsCreate(string $status): bool
{
return $status === 'D';
}
public function needsCancel(string $status): bool
{
return $status === 'E';
}
public function needsCommit(string $status): bool
{
return $status === 'F';
}
}
interface ResolvingStrategy
{
public function needsCreate(string $status): bool;
public function needsCancel(string $status): bool;
public function needsCommit(string $status): bool;
}
$subFactory->supports()
?