Passed
Push — master ( 9f7d35...3f1c7e )
by Wilmer
08:50 queued 06:32
created

IsOneOfAssert::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\TestUtility;
6
7
use PHPUnit\Framework\Constraint\Constraint;
8
use Yiisoft\VarDumper\VarDumper;
9
10
use function array_map;
11
use function implode;
12
use function in_array;
13
14
/**
15
 * IsOneOfAssert asserts that the value is one of the expected values.
16
 */
17
final class IsOneOfAssert extends Constraint
18
{
19
    private array $allowedValues;
20
21 7
    public function __construct(array $allowedValues)
22
    {
23 7
        $this->allowedValues = $allowedValues;
24 7
    }
25
26
    /**
27
     * Returns a string representation of the object.
28
     *
29
     * @return string
30
     */
31
    public function toString(): string
32
    {
33
        $allowedValues = array_map(static function ($value) {
34
            return VarDumper::dumpAsString($value);
0 ignored issues
show
Bug introduced by
The method dumpAsString() does not exist on Yiisoft\VarDumper\VarDumper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
            return VarDumper::/** @scrutinizer ignore-call */ dumpAsString($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        }, $this->allowedValues);
36
37
        $expectedAsString = implode(', ', $allowedValues);
38
39
        return "is one of $expectedAsString";
40
    }
41
42 7
    protected function matches($other): bool
43
    {
44 7
        return in_array($other, $this->allowedValues, false);
45
    }
46
}
47