HttpMessageMarkupExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 14.29%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 44
ccs 2
cts 14
cp 0.1429
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 6 1
A markup() 0 21 3
A getName() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Collector\Twig;
6
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFilter;
9
10
/**
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class HttpMessageMarkupExtension extends AbstractExtension
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @return array
19
     */
20 1
    public function getFilters()
21
    {
22
        return [
23 1
            new TwigFilter('httplug_markup', [$this, 'markup'], ['is_safe' => ['html']]),
24
        ];
25
    }
26
27
    /**
28
     * @param string $message http message
29
     */
30
    public function markup($message)
31
    {
32
        @trigger_error('"httplug_markup" twig extension is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
33
34
        $safeMessage = htmlentities($message);
35
        $parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);
36
37
        if (!isset($parts[1])) {
38
            // This is not a HTTP message
39
            return $safeMessage;
40
        }
41
42
        if (empty($parts[1])) {
43
            $parts[1] = '(This message has no captured body)';
44
        }
45
46
        // make header names bold
47
        $headers = preg_replace("|\n(.*?): |si", "\n<b>$1</b>: ", $parts[0]);
48
49
        return sprintf("%s\n\n<div class='httplug-http-body httplug-hidden'>%s</div>", $headers, $parts[1]);
50
    }
51
52
    public function getName()
53
    {
54
        return 'httplug.message_markup';
55
    }
56
}
57