Test Failed
Push — master ( 81711e...bf8774 )
by Sebastian
03:41
created

Mailcode_Traits_Formatting_HTMLHighlighting   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 61
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A excludeTag() 0 10 2
A isTagExcluded() 0 5 1
A getReplaceString() 0 3 1
A excludeTags() 0 8 2
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Traits_Formatting_HTMLHighlighting} trait.
4
 *
5
 * @package Mailcode
6
 * @subpackage Parser
7
 * @see Mailcode_Traits_Formatting_HTMLHighlighting
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Trait for HTML Highlighting formatters. This is a 
16
 * good solution to share this functionality between
17
 * different types (like the MarkVariables and HTMLHighlighting
18
 * formatters, since they extend different classes).
19
 *
20
 * @package Mailcode
21
 * @subpackage Parser
22
 * @author Sebastian Mordziol <[email protected]>
23
 */
24
trait Mailcode_Traits_Formatting_HTMLHighlighting
25
{
26
    /**
27
     * @var string[]
28
     */
29
    private $excludeTags = array(
30
        'style', // NOTE: style tags are excluded natively on the parser level.
31
        'script'
32
    );
33
    
34
   /**
35
    * Adds an HTML tag name to the list of tags within which
36
    * commands may not be highlighted.
37
    *
38
    * @param string $tagName Case insensitive.
39
    * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
40
    */
41
    public function excludeTag(string $tagName) : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
42
    {
43
        $tagName = strtolower($tagName);
44
        
45
        if(!in_array($tagName, $this->excludeTags))
46
        {
47
            $this->excludeTags[] = $tagName;
48
        }
49
        
50
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mailcode\Mailcode_Traits...atting_HTMLHighlighting which includes types incompatible with the type-hinted return Mailcode\Mailcode_Parser...r_Type_HTMLHighlighting.
Loading history...
51
    }
52
    
53
   /**
54
    * Adds several exluded tag names at once.
55
    *
56
    * @param string[] $tagNames
57
    * @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
58
    */
59
    public function excludeTags(array $tagNames) : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting
60
    {
61
        foreach($tagNames as $tagName)
62
        {
63
            $this->excludeTag((string)$tagName);
64
        }
65
        
66
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Mailcode\Mailcode_Traits...atting_HTMLHighlighting which includes types incompatible with the type-hinted return Mailcode\Mailcode_Parser...r_Type_HTMLHighlighting.
Loading history...
67
    }
68
    
69
   /**
70
    * Whether the specified tag name is in the exlusion list.
71
    *
72
    * @param string $tagName
73
    * @return bool
74
    */
75
    public function isTagExcluded(string $tagName) : bool
76
    {
77
        $tagName = strtolower($tagName);
78
        
79
        return in_array($tagName, $this->excludeTags);
80
    }
81
    
82
    public function getReplaceString(Mailcode_Parser_Safeguard_Formatter_Location $location): string
83
    {
84
        return $location->getPlaceholder()->getHighlightedText();
85
    }
86
}
87