diff --git a/src/State.php b/src/State.php index 532a287..55792c3 100644 --- a/src/State.php +++ b/src/State.php @@ -107,6 +107,12 @@ final class State implements StateBearer return $this; } + /** @return self */ + public static function fromState(State $State) + { + return $State; + } + public function isolatedCopy(): self { return new self(\array_map( diff --git a/src/StateBearer.php b/src/StateBearer.php index f0f9190..dc29cf3 100644 --- a/src/StateBearer.php +++ b/src/StateBearer.php @@ -5,4 +5,6 @@ namespace Erusev\Parsedown; interface StateBearer { public function state(): State; + /** @return static */ + public static function fromState(State $State); } diff --git a/tests/src/StateTest.php b/tests/src/StateTest.php index babb419..b9631f6 100644 --- a/tests/src/StateTest.php +++ b/tests/src/StateTest.php @@ -39,4 +39,16 @@ final class StateTest extends TestCase { $this->assertInstanceOf(State::class, clone(new State)); } + + /** + * @return void + * @throws \PHPUnit\Framework\Exception + * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + */ + public function testStateFromStateIdentical() + { + $State = new State; + + $this->assertSame($State, State::fromState($State)); + } }