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

IsOneOfAssert::toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
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