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

EncodeFormatter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 1
c 2
b 1
f 0
lcom 1
cbo 0
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 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