Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework\Constraint;
11
 
12
use function count;
13
use function gettype;
14
use function sprintf;
15
use function strpos;
16
use Countable;
17
use EmptyIterator;
18
 
19
/**
20
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
21
 */
22
final class IsEmpty extends Constraint
23
{
24
    /**
25
     * Returns a string representation of the constraint.
26
     */
27
    public function toString(): string
28
    {
29
        return 'is empty';
30
    }
31
 
32
    /**
33
     * Evaluates the constraint for parameter $other. Returns true if the
34
     * constraint is met, false otherwise.
35
     *
36
     * @param mixed $other value or object to evaluate
37
     */
38
    protected function matches($other): bool
39
    {
40
        if ($other instanceof EmptyIterator) {
41
            return true;
42
        }
43
 
44
        if ($other instanceof Countable) {
45
            return count($other) === 0;
46
        }
47
 
48
        return empty($other);
49
    }
50
 
51
    /**
52
     * Returns the description of the failure.
53
     *
54
     * The beginning of failure messages is "Failed asserting that" in most
55
     * cases. This method should return the second part of that sentence.
56
     *
57
     * @param mixed $other evaluated value or object
58
     */
59
    protected function failureDescription($other): string
60
    {
61
        $type = gettype($other);
62
 
63
        return sprintf(
64
            '%s %s %s',
65
            strpos($type, 'a') === 0 || strpos($type, 'o') === 0 ? 'an' : 'a',
66
            $type,
67
            $this->toString()
68
        );
69
    }
70
}