Passed
Pull Request — master (#380)
by Wilmer
02:46
created

IsOneOfAssert::toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
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
 * IsOneOfAssert asserts that the value is one of the expected values.
15
 */
16
final class IsOneOfAssert extends Constraint
17
{
18
    public function __construct(private array $allowedValues)
19
    {
20
    }
21
22
    /**
23
     * Returns a string representation of the object.
24
     */
25
    public function toString(): string
26
    {
27
        $allowedValues = [];
28
29
        foreach ($this->allowedValues as $value) {
30
            $this->allowedValues[] = VarDumper::create($value)->asString();
31
        }
32
33
        $expectedAsString = implode(', ', $allowedValues);
34
35
        return "is one of $expectedAsString";
36
    }
37
38
    protected function matches($other): bool
39
    {
40
        return in_array($other, $this->allowedValues, false);
41
    }
42
}
43