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;
11
 
12
use function debug_backtrace;
13
use function in_array;
14
use function lcfirst;
15
use function sprintf;
16
 
17
/**
18
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
19
 */
20
final class InvalidArgumentException extends Exception
21
{
22
    public static function create(int $argument, string $type): self
23
    {
24
        $stack    = debug_backtrace();
25
        $function = $stack[1]['function'];
26
 
27
        if (isset($stack[1]['class'])) {
28
            $function = sprintf('%s::%s', $stack[1]['class'], $stack[1]['function']);
29
        }
30
 
31
        return new self(
32
            sprintf(
33
                'Argument #%d of %s() must be %s %s',
34
                $argument,
35
                $function,
36
                in_array(lcfirst($type)[0], ['a', 'e', 'i', 'o', 'u'], true) ? 'an' : 'a',
37
                $type
38
            )
39
        );
40
    }
41
 
42
    private function __construct(string $message = '', int $code = 0, \Exception $previous = null)
43
    {
44
        parent::__construct($message, $code, $previous);
45
    }
46
}