Passed
Push — master ( 839bc4...44fbc3 )
by Alec
02:53
created

Strip   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 3
b 0
f 0
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A controlCodes() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core;
4
5
class Strip
6
{
7
    protected const REG_EXP = '#\\x1b[[][^A-Za-z]*[A-Za-z]#';
8
9
    /**
10
     * @param string $in
11
     * @return string
12
     */
13 36
    public static function controlCodes(string $in): string
14
    {
15 36
        $str = preg_replace(self::REG_EXP, '', $in);
16 36
        if (PREG_NO_ERROR !== $error = preg_last_error()) {
17
            // @codeCoverageIgnoreStart
18
            throw new \RuntimeException('Failed to apply regex. Code: ' . $error, $error);
19
            // @codeCoverageIgnoreEnd
20
        }
21 36
        return (string)$str;
22
    }
23
}
24