Completed
Push — master ( ab502e...07a33d )
by Zaahid
06:14
created

HeaderPart   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 91.67%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 6
c 3
b 2
f 0
lcom 0
cbo 0
dl 0
loc 65
ccs 11
cts 12
cp 0.9167
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 4 1
A __toString() 0 4 1
A ignoreSpacesAfter() 0 4 1
A convertEncoding() 0 7 2
A ignoreSpacesBefore() 0 4 1
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace ZBateson\MailMimeParser\Header\Part;
8
9
/**
10
 * Abstract base class representing a single part of a parsed header.
11
 *
12
 * @author Zaahid Bateson
13
 */
14
abstract class HeaderPart
15
{
16
    /**
17
     * @var string the value of the part
18
     */
19
    protected $value;
20
21
    /**
22
     * Returns the part's value.
23
     * 
24
     * @return string the value of the part
25
     */
26 13
    public function getValue()
27
    {
28 13
        return $this->value;
29
    }
30
    
31
    /**
32
     * Returns the value of the part (which is a string).
33
     * 
34
     * @return string the value
35
     */
36 2
    public function __toString()
37
    {
38 2
        return $this->value;
39
    }
40
    
41
    /**
42
     * Returns true if spaces before this part should be ignored.  True is only
43
     * returned for MimeLiterals if the part begins with a mime-encoded string,
44
     * Tokens if the Token's value is a single space, and for CommentParts.
45
     * 
46
     * @return bool
47
     */
48 1
    public function ignoreSpacesBefore()
49
    {
50 1
        return false;
51
    }
52
    
53
    /**
54
     * Returns true if spaces after this part should be ignored.  True is only
55
     * returned for MimeLiterals if the part ends with a mime-encoded string
56
     * Tokens if the Token's value is a single space, and for CommentParts.
57
     * 
58
     * @return bool
59
     */
60 1
    public function ignoreSpacesAfter()
61
    {
62 1
        return false;
63
    }
64
    
65
    /**
66
     * Ensures the encoding of the passed string is set to UTF-8.
67
     * 
68
     * @param string $str
69
     * @return string utf-8 string
70
     */
71 18
    protected function convertEncoding($str)
72
    {
73 18
        if (!mb_check_encoding($str, 'UTF-8')) {
74
            return mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
75
        }
76 18
        return $str;
77
    }
78
}
79