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 strlen;
13
use function strpos;
14
use PHPUnit\Framework\InvalidArgumentException;
15
 
16
/**
17
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
18
 */
19
final class StringStartsWith extends Constraint
20
{
21
    /**
22
     * @var string
23
     */
24
    private $prefix;
25
 
26
    public function __construct(string $prefix)
27
    {
28
        if (strlen($prefix) === 0) {
29
            throw InvalidArgumentException::create(1, 'non-empty string');
30
        }
31
 
32
        $this->prefix = $prefix;
33
    }
34
 
35
    /**
36
     * Returns a string representation of the constraint.
37
     */
38
    public function toString(): string
39
    {
40
        return 'starts with "' . $this->prefix . '"';
41
    }
42
 
43
    /**
44
     * Evaluates the constraint for parameter $other. Returns true if the
45
     * constraint is met, false otherwise.
46
     *
47
     * @param mixed $other value or object to evaluate
48
     */
49
    protected function matches($other): bool
50
    {
51
        return strpos((string) $other, $this->prefix) === 0;
52
    }
53
}