GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

State   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 74
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A flatMap() 0 9 1
A of() 0 3 1
A run() 0 3 1
A __construct() 0 3 1
A map() 0 9 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Immutable;
5
6
use Innmind\Immutable\State\Result;
7
8
/**
9
 * @psalm-immutable
10
 * @template S
11
 * @template T
12
 */
13
final class State
14
{
15
    /** @var callable(S): Result<S, T> */
16
    private $run;
17
18
    /**
19
     * @param callable(S): Result<S, T> $run
20
     */
21
    private function __construct(callable $run)
22
    {
23
        $this->run = $run;
24
    }
25
26
    /**
27
     * @psalm-pure
28
     * @template A
29
     * @template B
30
     *
31
     * @param callable(A): Result<A, B> $run
32
     *
33
     * @return self<A, B>
34
     */
35
    public static function of(callable $run): self
36
    {
37
        return new self($run);
38
    }
39
40
    /**
41
     * @template U
42
     *
43
     * @param callable(T): U $map
44
     *
45
     * @return self<S, U>
46
     */
47
    public function map(callable $map): self
48
    {
49
        $run = $this->run;
50
51
        return new self(static function(mixed $state) use ($run, $map) {
52
            /** @var S $state */
53
            $result = $run($state);
54
55
            return Result::of($result->state(), $map($result->value()));
56
        });
57
    }
58
59
    /**
60
     * @template A
61
     * @template B
62
     *
63
     * @param callable(T): self<A, B> $map
64
     *
65
     * @return self<A, B>
66
     */
67
    public function flatMap(callable $map): self
68
    {
69
        $run = $this->run;
70
71
        return new self(static function(mixed $state) use ($run, $map) {
72
            /** @var S $state */
73
            $result = $run($state);
74
75
            return $map($result->value())->run($result->state());
76
        });
77
    }
78
79
    /**
80
     * @param S $state
81
     *
82
     * @return Result<S, T>
83
     */
84
    public function run($state): Result
85
    {
86
        return ($this->run)($state);
87
    }
88
}
89