Valinor/tests/Fake/Mapper/Tree/Visitor/FakeShellVisitor.php

34 lines
697 B
PHP
Raw Normal View History

2021-11-28 17:43:02 +01:00
<?php
declare(strict_types=1);
namespace CuyZ\Valinor\Tests\Fake\Mapper\Tree\Visitor;
use CuyZ\Valinor\Mapper\Tree\Shell;
use CuyZ\Valinor\Mapper\Tree\Visitor\ShellVisitor;
final class FakeShellVisitor implements ShellVisitor
{
/** @var null|callable(Shell): Shell */
private $callback;
/**
* @param null|callable(Shell): Shell $callback
*/
public function __construct(callable $callback = null)
{
if ($callback) {
$this->callback = $callback;
}
}
public function visit(Shell $shell): Shell
{
if (! isset($this->callback)) {
return $shell;
}
return ($this->callback)($shell);
}
}