UnresolvedMatchSubject   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A done() 0 3 1
A case() 0 7 1
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