Header   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rule() 0 3 1
A render() 0 8 1
1
<?php # -*- coding: utf-8 -*-
2
declare(strict_types=1);
3
4
namespace Bueltge\Marksimple\Rule;
5
6
class Header extends AbstractRegexRule
7
{
8
9
    /**
10
     * Get the regex rule to identify the fromFile for the callback.
11
     * Header h1 - h6.
12
     *
13
     * @return string
14
     */
15 12
    public function rule(): string
16 12
    {
17 12
        return '#^(\#{1,6})\s*([^\#]+?)\s*\#*$#m';
18
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 9
    public function render(array $content): string
24 9
    {
25 9
        $headingLevel = \strlen($content[1]);
26 9
        $header = trim($content[2]);
27
        // Build anker without space, numbers.
28 9
        $anker = preg_replace('#[^a-z?!]#', '', strtolower($header));
29
30 9
        return sprintf('<h%d id="%s">%s</h%d>', $headingLevel, $anker, $header, $headingLevel);
31
    }
32
}
33