ContentParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 3
c 2
b 0
f 1
dl 0
loc 8
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\Twig\Parser;
13
14
use Symfony\Contracts\Translation\TranslatorInterface;
15
16
final class ContentParser implements ContentParserInterface
17
{
18
    /** @var \Twig_Environment */
19
    private $twigEnvironment;
20
21
    /** @var array */
22
    private $enabledFunctions;
23
24
    /** @var TranslatorInterface */
25
    private $translator;
26
27
    public function __construct(
28
        \Twig_Environment $twigEnvironment,
29
        array $enabledFunctions,
30
        TranslatorInterface $translator
31
    ) {
32
        $this->twigEnvironment = $twigEnvironment;
33
        $this->enabledFunctions = $enabledFunctions;
34
        $this->translator = $translator;
35
    }
36
37
    public function parse(string $input, string $argument): string
38
    {
39
        preg_match_all('`{{\s*(?P<arguments>.+)\s*}}`', $input, $callMatches);
40
41
        foreach ($callMatches[0] as $index => $call) {
42
            $input = str_replace($call, $argument, $input);
43
        }
44
45
        return $input;
46
    }
47
}
48