123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- declare(strict_types=1);
- /**
- * This file is part of Hyperf.
- *
- * @link https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact group@hyperf.io
- * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
- namespace Hyperf\Testing\Exception;
- use PHPUnit\Framework\Exception;
- class InvalidArgumentException extends Exception
- {
- /**
- * Creates a new exception for an invalid argument.
- */
- public static function create(int $argument, string $type): static
- {
- $stack = debug_backtrace();
- $function = $stack[1]['function'];
- if (isset($stack[1]['class'])) {
- $function = sprintf('%s::%s', $stack[1]['class'], $stack[1]['function']);
- }
- return new static(
- sprintf(
- 'Argument #%d of %s() must be %s %s',
- $argument,
- $function,
- in_array(lcfirst($type)[0], ['a', 'e', 'i', 'o', 'u'], true) ? 'an' : 'a',
- $type
- )
- );
- }
- }
|