Completed
Push — master ( 4bb011...4b99be )
by Guillaume
13:23
created

HtmlToTxtRender::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
namespace Starkerxp\CampaignBundle\Render;
5
6
class HtmlToTxtRender extends AbstractRender
7
{
8
    /**
9
     * @var \HTMLPurifier
10
     */
11
    private $htmlPurifierService;
12
13
    /**
14
     * HtmlToTxtRender constructor.
15
     *
16
     * @param \HTMLPurifier $htmlPurifierService
17
     */
18
    public function __construct(\HTMLPurifier $htmlPurifierService)
19
    {
20
        $this->htmlPurifierService = $htmlPurifierService;
21
    }
22
23
    public function render()
24
    {
25
        $monTexte = preg_replace("#\<[[:space:]]?br[[:space:]]?\/?[[:space:]]?>#", "<br/>\n", $this->getContenu());
26
        $monTexte = preg_replace("#\<\/[[:space:]]?p[[:space:]]?>#", "</p>\n\n", $monTexte);
27
        $monTexte = preg_replace("#\<\/[[:space:]]?div[[:space:]]?>#", "</div>\n\n", $monTexte);
28
        $monTexte = $this->htmlPurifierService->purify(
29
            $monTexte,
30
            [
0 ignored issues
show
Documentation introduced by
array('AutoFormat.DisplayLinkURI' => true) is of type array<string,boolean,{"A...layLinkURI":"boolean"}>, but the function expects a object<HTMLPurifier_Config>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
                'AutoFormat.DisplayLinkURI' => true,
32
            ]
33
        );
34
        $monTexte = strip_tags($monTexte);
35
        $monTexte = implode(
36
            "\n",
37
            array_map(
38
                function ($ligne) {
39
                    return trim($ligne);
40
                },
41
                explode("\n", $monTexte)
42
            )
43
        );
44
        $monTexte = str_replace(["[{@mirror}]", "[{@pixel}]"], "", $monTexte);
45
46
        return $monTexte;
47
    }
48
49
    public function getSupport($api, $version)
50
    {
51
        return empty($api) && $version == 'txt';
52
    }
53
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
54