Passed
Pull Request — master (#1676)
by Arnaud
09:49 queued 04:14
created

HtmlExcerpt   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Cecil\Renderer\PostProcessor;
15
16
use Cecil\Collection\Page\Page;
17
18
/**
19
 * HtmlExcerpt class.
20
 *
21
 * Replaces excerpt or break tag by HTML anchor.
22
 */
23
class HtmlExcerpt extends AbstractPostProcessor
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function process(Page $page, string $output, string $format): string
29
    {
30 1
        if ($format == 'html') {
31
            // https://regex101.com/r/Xl7d5I/3
32 1
            $pattern = '(.*)(<!--[[:blank:]]?(excerpt|break)[[:blank:]]?-->)(.*)';
33 1
            $replacement = '$1<span id="more"></span>$4';
34 1
            $excerpt = preg_replace('/' . $pattern . '/is', $replacement, $output, 1);
35 1
            $output = $excerpt ?? $output;
36
        }
37
38 1
        return $output;
39
    }
40
}
41