DefinedConstantsValueHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace Enjoys\Config\ValueHandler;
7
8
9
use Enjoys\Config\ValueHandlerInterface;
10
11
final class DefinedConstantsValueHandler implements ValueHandlerInterface
12
{
13
14
    /**
15
     * @psalm-suppress MixedArgumentTypeCoercion
16
     */
17 22
    public function handle(string $input): string
18
    {
19 22
        return preg_replace_callback(
20 22
            '/(%)(.+)(%)/',
21 22
            function ($matches) {
22 1
                if (\defined($matches[2])) {
23 1
                    return constant($matches[2]);
24
                }
25 1
                return $matches[1] . $matches[2] . $matches[3];
26 22
            },
27 22
            $input
28 22
        ) ?? '';
29
    }
30
}
31