Passed
Push — master ( 40ca60...430c98 )
by Sebastian
02:56
created

Mailcode_Parser_Safeguard_Formatter_SingleLines::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 39
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 18
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 39
rs 9.6666

1 Method

Rating   Name   Duplication   Size   Complexity  
A Mailcode_Parser_Safeguard_Formatter_SingleLines::getReplaceNeedle() 0 3 1
1
<?php
2
/**
3
 * File containing the {@see Mailcode_Parser_Safeguard_Formatter_SingleLines} class.
4
 *
5
 * @package Mailcode
6
 * @subpackage Parser
7
 * @see Mailcode_Parser_Safeguard_Formatter_SingleLines
8
 */
9
10
declare(strict_types=1);
11
12
namespace Mailcode;
13
14
/**
15
 * Single line formatter: ensures that all commands in the
16
 * subject string are placed on a separate line. This is 
17
 * typically used when using a custom parser for HTML documents,
18
 * to make it easier to identify commands.
19
 *
20
 * @package Mailcode
21
 * @subpackage Parser
22
 * @author Sebastian Mordziol <[email protected]>
23
 */
24
class Mailcode_Parser_Safeguard_Formatter_SingleLines extends Mailcode_Parser_Safeguard_Formatter
25
{
26
   /**
27
    * @var string
28
    */
29
    private $eol;
30
    
31
   /**
32
    * @var int
33
    */
34
    private $eolLength;
35
    
36
    protected function initFormatting(string $subject) : string
37
    {
38
        $this->eol = $this->resolveNewlineChar($subject);
39
        $this->eolLength = strlen($this->eol);
40
        
41
        return $subject;
42
    }
43
    
44
    public function getEOLChar() : string
45
    {
46
        return $this->eol;
47
    }
48
    
49
    public function getEOLLength() : int
50
    {
51
        return $this->eolLength;
52
    }
53
54
   /**
55
    * We only use placeholders that contain commands that do
56
    * not generate contents, since these are the only ones
57
    * that may need adjusting.
58
    * 
59
    * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[]
60
    */
61
    protected function filterPlaceholders()
62
    {
63
        $placeholders = $this->safeguard->getPlaceholders();
64
        
65
        $result = array();
66
        
67
        foreach($placeholders as $placeholder)
68
        {
69
            if(!$placeholder->getCommand()->generatesContent())
70
            {
71
                $result[] = $placeholder;
72
            }
73
        }
74
        
75
        return $result;
76
    }
77
    
78
    public function getReplaceNeedle(Mailcode_Parser_Safeguard_Placeholder $placeholder) : string
79
    {
80
        return $placeholder->getReplacementText();
81
    }
82
}
83
84