UnresolvedMatchSubject::done()   A
last analyzed

Complexity

Conditions 1
Paths 0

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 0
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Scalp\PatternMatching;
6
7
use Scalp\PatternMatching\Exception\PatternMatchingSubjectNotFound;
8
use Scalp\PatternMatching\Pattern\Pattern;
9
10
final class UnresolvedMatchSubject extends MatchSubject
11
{
12
    public function case(Pattern $pattern, callable $handler): MatchSubject
13
    {
14
        return $pattern
15
            ->match($this->get())
16
            ->fold(
17
                function (): MatchSubject { return $this; },
18
                function ($result) use ($handler): MatchSubject { return new ResolvedMatchSubject($handler(...$result)); }
19
            );
20
    }
21
22
    public function done(): void
23
    {
24
        throw PatternMatchingSubjectNotFound::for($this->get());
25
    }
26
}
27