Passed
Push — master ( c423ac...6bd0a6 )
by Enjoys
10:06
created

DefinedConstantsValueHandler::handle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
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
    public function handle(string $input): string
18
    {
19
        return preg_replace_callback(
20
            '/(%)(.+)(%)/',
21
            function ($matches) {
22
                if (\defined($matches[2])) {
23
                    return constant($matches[2]);
24
                }
25
                return $matches[1] . $matches[2] . $matches[3];
26
            },
27
            $input
28
        );
29
    }
30
}
31