Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Comparable
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 is
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNot
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 in
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 notIn
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Ergonomic utilities for PHP enums, including names, values, lookups, and option maps.
7 *
8 * This file is part of fast-forward/enum project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/enum
14 * @see      https://github.com/php-fast-forward/enum/issues
15 * @see      https://php-fast-forward.github.io/enum/
16 * @see      https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Enum\Trait;
20
21trait Comparable
22{
23    /**
24     * @param self $other
25     *
26     * @return bool
27     */
28    public function is(self $other): bool
29    {
30        return $this === $other;
31    }
32
33    /**
34     * @param self $other
35     *
36     * @return bool
37     */
38    public function isNot(self $other): bool
39    {
40        return $this !== $other;
41    }
42
43    /**
44     * @param list<self> $cases
45     */
46    public function in(array $cases): bool
47    {
48        return \in_array($this, $cases, true);
49    }
50
51    /**
52     * @param list<self> $cases
53     */
54    public function notIn(array $cases): bool
55    {
56        return ! $this->in($cases);
57    }
58}