Passed
Push — master ( 8807b4...37e483 )
by Wilmer
03:08
created

IsOneOfAssert   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 1
A __construct() 0 2 1
A toString() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Support;
6
7
use PHPUnit\Framework\Constraint\Constraint;
8
use Yiisoft\VarDumper\VarDumper;
9
10
use function implode;
11
use function in_array;
12
13
/**
14
 * @psalm-suppress PropertyNotSetInConstructor
15
 */
16
final class IsOneOfAssert extends Constraint
17
{
18
    /** @psalm-param string[] $allowedValues */
19
    public function __construct(private array $allowedValues)
20
    {
21
    }
22
23
    /**
24
     * Returns a string representation of the object.
25
     */
26
    public function toString(): string
27
    {
28
        $allowedValues = [];
29
30
        foreach ($this->allowedValues as $value) {
31
            $this->allowedValues[] = VarDumper::create($value)->asString();
32
        }
33
34
        $expectedAsString = implode(', ', $allowedValues);
35
36
        return "is one of $expectedAsString";
37
    }
38
39
    protected function matches($other): bool
40
    {
41
        return in_array($other, $this->allowedValues);
42
    }
43
}
44