Completed
Pull Request — develop (#32)
by Michael
06:53
created

EncodeFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Crummy\Phlack\Common\Formatter;
4
5
class EncodeFormatter implements FormatterInterface
6
{
7
    private $guards = ['^(', ')^'];
8
9
    /**
10
     * @param string $text
11
     *
12
     * @return string
13
     */
14 2
    public function format($text)
15
    {
16 2
        $replacement = implode('', [$this->guards[0], '$1', $this->guards[1]]);
17 2
        $text = preg_replace('/<(.*)>/U', $replacement, $text);
18 2
        $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8', false);
19
20 2
        return str_replace($this->guards, ['<', '>'], $text);
21
    }
22
}
23