PcreRegexException::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 3
crap 3
1
<?php
2
3
namespace Gobie\Regex\Wrappers\Pcre;
4
5
use Gobie\Regex\Wrappers\RegexException;
6
7
class PcreRegexException extends RegexException
8
{
9
10
    public static $messages = array(
11
        \PREG_INTERNAL_ERROR        => 'Internal error',
12
        \PREG_BACKTRACK_LIMIT_ERROR => 'Backtrack limit was exhausted',
13
        \PREG_RECURSION_LIMIT_ERROR => 'Recursion limit was exhausted',
14
        \PREG_BAD_UTF8_ERROR        => 'Malformed UTF-8 data',
15
        // HHVM fix, constant PREG_BAD_UTF8_OFFSET_ERROR replaced by its number
16
        5                           => 'The offset didn\'t correspond to the begin of a valid UTF-8 code point',
17
    );
18
19
    /**
20
     * If code is provided, but no message, it uses default PREG error messages.
21
     *
22
     * @param string               $message Message
23
     * @param int|null             $code    Code
24
     * @param string|string[]|null $pattern Pattern
25
     */
26 63
    public function __construct($message, $code = null, $pattern = null)
27
    {
28 63
        if (!$message && isset(self::$messages[$code])) {
29 18
            $message = self::$messages[$code];
30
        }
31
32 63
        parent::__construct($message, $code, $pattern);
33 63
    }
34
}
35