DefinedConstantsValueHandler::handle()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 10
cts 10
cp 1
crap 2
rs 10
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