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.

Identity::ensureHeldBy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 13
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 21
rs 9.8333
1
<?php
2
declare(strict_types = 1);
3
4
namespace Properties\Innmind\Immutable\Monoid;
5
6
use Innmind\BlackBox\{
7
    Set,
8
    Property,
9
};
10
use PHPUnit\Framework\Assert;
11
12
/**
13
 * @template T
14
 */
15
final class Identity implements Property
16
{
17
    /** @var T */
0 ignored issues
show
Bug introduced by
The type Properties\Innmind\Immutable\Monoid\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
    private mixed $value;
19
    /** @var callable(T, T): bool */
20
    private $equals;
21
22
    /**
23
     * @param T $value
24
     * @param callable(T, T): bool $equals
25
     */
26
    public function __construct(mixed $value, callable $equals)
27
    {
28
        $this->value = $value;
29
        $this->equals = $equals;
30
    }
31
32
    /**
33
     * @template A
34
     *
35
     * @param Set<A> $values
36
     * @param callable(A, A): bool $equals
37
     *
38
     * @return Set<self<A>>
39
     */
40
    public static function any(Set $values, callable $equals): Set
41
    {
42
        return Set\Decorate::immutable(
43
            static fn($value) => new self($value, $equals),
44
            $values,
45
        );
46
    }
47
48
    public function name(): string
49
    {
50
        return 'Identity value has no effect on the combined value';
51
    }
52
53
    public function applicableTo(object $monoid): bool
54
    {
55
        return true;
56
    }
57
58
    public function ensureHeldBy(object $monoid): object
59
    {
60
        Assert::assertTrue(($this->equals)(
61
            $monoid->identity(),
62
            $monoid->identity(),
63
        ));
64
        Assert::assertTrue(($this->equals)(
65
            $this->value,
66
            $monoid->combine($monoid->identity(), $this->value),
67
        ));
68
        Assert::assertTrue(($this->equals)(
69
            $this->value,
70
            $monoid->combine($this->value, $monoid->identity()),
71
        ));
72
        // make sure the identiy is not altered after using a concrete value
73
        Assert::assertTrue(($this->equals)(
74
            $monoid->identity(),
75
            $monoid->identity(),
76
        ));
77
78
        return $monoid;
79
    }
80
}
81