Completed
Push — master ( 80ce05...3bd469 )
by David
09:43 queued 10s
created

HttpMessageMarkupExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Http\HttplugBundle\Collector\Twig;
4
5
/**
6
 * @author Tobias Nyholm <[email protected]>
7
 */
8
class HttpMessageMarkupExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
9
{
10
    /**
11
     * {@inheritdoc}
12
     *
13
     * @return array
14
     */
15 1
    public function getFilters()
16
    {
17
        return [
18 1
            new \Twig_SimpleFilter('httplug_markup', [$this, 'markup'], ['is_safe' => ['html']]),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFilter has been deprecated with message: since Twig 2.7, use "Twig\TwigFilter" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
19
        ];
20
    }
21
22
    /**
23
     * @param string $message http message
24
     */
25
    public function markup($message)
26
    {
27
        @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...
28
29
        $safeMessage = htmlentities($message);
30
        $parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);
31
32
        if (!isset($parts[1])) {
33
            // This is not a HTTP message
34
            return $safeMessage;
35
        }
36
37
        if (empty($parts[1])) {
38
            $parts[1] = '(This message has no captured body)';
39
        }
40
41
        // make header names bold
42
        $headers = preg_replace("|\n(.*?): |si", "\n<b>$1</b>: ", $parts[0]);
43
44
        return sprintf("%s\n\n<div class='httplug-http-body httplug-hidden'>%s</div>", $headers, $parts[1]);
45
    }
46
47
    public function getName()
48
    {
49
        return 'httplug.message_markup';
50
    }
51
}
52