Completed
Push — master ( d87057...f3ab30 )
by Jaap
28s queued 12s
created

PcreException::createFromPhpError()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 8
nop 1
dl 0
loc 20
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Reflection\Exception;
6
7
use InvalidArgumentException;
8
use const PREG_BACKTRACK_LIMIT_ERROR;
9
use const PREG_BAD_UTF8_ERROR;
10
use const PREG_BAD_UTF8_OFFSET_ERROR;
11
use const PREG_INTERNAL_ERROR;
12
use const PREG_JIT_STACKLIMIT_ERROR;
13
use const PREG_NO_ERROR;
14
use const PREG_RECURSION_LIMIT_ERROR;
15
16
final class PcreException extends InvalidArgumentException
17
{
18
    public static function createFromPhpError(int $errorCode) : self
19
    {
20
        switch ($errorCode) {
21
            case PREG_BACKTRACK_LIMIT_ERROR:
22
                return new self('Backtrack limit error');
23
            case PREG_RECURSION_LIMIT_ERROR:
24
                return new self('Recursion limit error');
25
            case PREG_BAD_UTF8_ERROR:
26
                return new self('Bad UTF8 error');
27
            case PREG_BAD_UTF8_OFFSET_ERROR:
28
                return new self('Bad UTF8 offset error');
29
            case PREG_JIT_STACKLIMIT_ERROR:
30
                return new self('Jit stacklimit error');
31
            case PREG_NO_ERROR:
32
            case PREG_INTERNAL_ERROR:
33
            default:
34
        }
35
36
        return new self('Unknown Pcre error');
37
    }
38
}
39