Passed
Pull Request — master (#843)
by butschster
07:09
created

NullLocaleProcessor   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 1
b 0
f 0
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Stempler\Processor;
6
7
use Spiral\Views\ContextInterface;
8
use Spiral\Views\ProcessorInterface;
9
use Spiral\Views\ViewSource;
10
11
/**
12
 * The processor is used to remove brackets [[ ... ]] when the Translator component is not installed.
13
 */
14
final class NullLocaleProcessor implements ProcessorInterface
15
{
16
    private const REGEXP = '/\[\[(.*?)\]\]/s';
17
18 1
    public function process(ViewSource $source, ContextInterface $context): ViewSource
19
    {
20
        //We are not forcing locale for now
21 1
        return $source->withCode(
22 1
            \preg_replace_callback(
23
                self::REGEXP,
24 1
                static fn ($matches) => $matches[1],
25 1
                $source->getCode()
26
            )
27
        );
28
    }
29
}
30