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\Util;
11
 
12
use function in_array;
13
use function sprintf;
14
 
15
/**
16
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
17
 *
18
 * @psalm-immutable
19
 */
20
final class VersionComparisonOperator
21
{
22
    /**
23
     * @psalm-var '<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne'
24
     */
25
    private $operator;
26
 
27
    public function __construct(string $operator)
28
    {
29
        $this->ensureOperatorIsValid($operator);
30
 
31
        $this->operator = $operator;
32
    }
33
 
34
    /**
35
     * @return '!='|'<'|'<='|'<>'|'='|'=='|'>'|'>='|'eq'|'ge'|'gt'|'le'|'lt'|'ne'
36
     */
37
    public function asString(): string
38
    {
39
        return $this->operator;
40
    }
41
 
42
    /**
43
     * @throws Exception
44
     *
45
     * @psalm-assert '<'|'lt'|'<='|'le'|'>'|'gt'|'>='|'ge'|'=='|'='|'eq'|'!='|'<>'|'ne' $operator
46
     */
47
    private function ensureOperatorIsValid(string $operator): void
48
    {
49
        if (!in_array($operator, ['<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne'], true)) {
50
            throw new Exception(
51
                sprintf(
52
                    '"%s" is not a valid version_compare() operator',
53
                    $operator
54
                )
55
            );
56
        }
57
    }
58
}