RegexException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 44
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A getShortMessage() 0 9 2
1
<?php
2
3
namespace Gobie\Regex\Wrappers;
4
5
class RegexException extends \RuntimeException
6
{
7
8
    /**
9
     * If pattern is provided, it is appended to the message.
10
     *
11
     * @param string               $message Message
12
     * @param int|null             $code    Code
13
     * @param string|string[]|null $pattern Pattern
14
     */
15 82
    public function __construct($message, $code = null, $pattern = null)
16
    {
17 82
        if (!$message) {
18 3
            $message = 'Unknown error';
19
        }
20
21 82
        if ($pattern !== null) {
22 78
            $message .= '; pattern: ' . \implode(', ', (array) $pattern);
23
        }
24
25 82
        parent::__construct($message, $code);
26 82
    }
27
28
    /**
29
     * Return exception message without function name.
30
     *
31
     * Usual exception message looks like this:
32
     * <pre>
33
     * preg_match(): Some error occurred
34
     * </pre>
35
     * So we strip the "function(): " part.
36
     *
37
     * @return string
38
     */
39 76
    public function getShortMessage()
40
    {
41 76
        $msg = $this->getMessage();
42 76
        if (\strpos($msg, '(): ') !== false) {
43 57
            list(, $msg) = \explode('(): ', $msg);
44
        }
45
46 76
        return $msg;
47
    }
48
}
49