Test Failed
Push — feature-laravel-5.4 ( 61a401...1326fd )
by Kirill
03:29
created

HeadersNormalizer::normalizeHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\Services\ContentRenderer\Support;
10
11
/**
12
 * Class HeadersNormalizer.
13
 */
14
trait HeadersNormalizer
15
{
16
    /**
17
     * @var array
18
     */
19
    private $tags = [
20
        6 => 6,
21
        5 => 6,
22
        4 => 5,
23
        3 => 4,
24
        2 => 3,
25
        1 => 2,
26
    ];
27
28
    /**
29
     * @return \Closure
30
     */
31
    protected function normalizeHeaders(): \Closure
32
    {
33
        return function (string $body) {
34
            return preg_replace_callback('/^(#+)\s+(.*?)\s*$/mius', function (array $matches) {
35
                [$body, $level, $title] = $matches;
0 ignored issues
show
Bug introduced by
The variable $body does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $level does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $title does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
37
                $size = $this->tags[
38
                    max(1, min(6, strlen($level)))
39
                ];
40
41
                return str_repeat('#', $size) . ' ' . $title;
42
            }, $body);
43
        };
44
    }
45
}