PhpPlaceholder::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
ccs 8
cts 8
cp 1
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ArjanSchouten\HtmlMinifier\Placeholders\Php;
4
5
use ArjanSchouten\HtmlMinifier\Placeholders\PlaceholderInterface;
6
7
class PhpPlaceholder implements PlaceholderInterface
8
{
9
    /**
10
     * Replace PHP tags with a temporary placeholder.
11
     *
12
     * @param \ArjanSchouten\HtmlMinifier\MinifyContext $context
13
     *
14
     * @return \ArjanSchouten\HtmlMinifier\MinifyContext
15
     */
16 5
    public function process($context)
17
    {
18 5
        $contents = $context->getContents();
19
        $contents = preg_replace_callback('/<\?=((?!\?>).)*\?>/s', function ($match) use ($context) {
20 1
            return $context->getPlaceholderContainer()->createPlaceholder($match[0]);
21 5
        }, $contents);
22 5
        $contents = preg_replace_callback('/<\?php((?!\?>).)*(\?>)?/s', function ($match) use ($context) {
23 1
            return $context->getPlaceholderContainer()->createPlaceholder($match[0]);
24 5
        }, $contents);
25
26 5
        return $context->setContents($contents);
27
    }
28
}
29