Passed
Pull Request — master (#163)
by Wilmer
17:48 queued 02:54
created

IsOneOfAssert   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 3 1
A toString() 0 9 1
A __construct() 0 3 1
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
    public function __construct(array $allowedValues)
22
    {
23
        $this->allowedValues = $allowedValues;
24
    }
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
    protected function matches($other): bool
43
    {
44
        return in_array($other, $this->allowedValues, false);
45
    }
46
}
47