Passed
Push — master ( ab2034...9ae42c )
by Radu
01:57
created

SourceCode::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 2
1
<?php
2
namespace WebServCo\Framework;
3
4
final class SourceCode
5
{
6
    const TYPE_XML = 'XML';
7
8
    protected $type;
9
    protected $data;
10
11
    public function __construct($type, $data)
12
    {
13
        switch ($type) {
14
            case self::TYPE_XML:
15
                break;
16
            default:
17
                throw new \WebServCo\Framework\Exceptions\ApplicationException('Type not implemented');
18
                break;
19
        }
20
        $this->type = $type;
21
        $this->data = $data;
22
    }
23
24
    public function highlight()
25
    {
26
        switch ($this->type) {
27
            case self::TYPE_XML:
28
                return $this->highlightXml($this->data);
29
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
30
            default:
31
                return false;
32
                break;
33
        }
34
    }
35
36
    protected function highlightXml($data)
37
    {
38
        $data = htmlentities($data);
39
        $data = str_replace('&lt;', '<span style="color: purple">&lt;', $data);
40
        $data = str_replace('&gt;', '&gt;</span>', $data);
41
        return $data;
42
    }
43
}
44