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

Mailcode_Parser_Safeguard_FormatterLocation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlaceholderText() 0 10 2
A __construct() 0 6 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
 * Abstract safeguard formatter location: this is where the decision
16
 * is made whether a specific placeholder instance needs to be 
17
 * transformed according to the formatter. 
18
 *
19
 * @package Mailcode
20
 * @subpackage Parser
21
 * @author Sebastian Mordziol <[email protected]>
22
 */
23
abstract class Mailcode_Parser_Safeguard_FormatterLocation
24
{
25
   /**
26
    * @var Mailcode_Parser_Safeguard_Formatter
27
    */
28
    protected $formatter;
29
    
30
   /**
31
    * @var Mailcode_Parser_Safeguard_Placeholder_Locator_Location
32
    */
33
    protected $location;
34
    
35
    public function __construct(Mailcode_Parser_Safeguard_Formatter $formatter, Mailcode_Parser_Safeguard_Placeholder_Locator_Location $location)
36
    {
37
        $this->formatter = $formatter;
38
        $this->location = $location;
39
        
40
        $this->init();
41
    }
42
    
43
    abstract protected function init() : void; 
44
    
45
   /**
46
    * Whether this specific placeholder location needs to be adjusted.
47
    * 
48
    * @return bool
49
    */
50
    abstract public function requiresAdjustment() : bool;
51
    
52
    abstract protected function getAdjustedText() : string;
53
    
54
   /**
55
    * Retrieves the placeholder text, adjusted as needed by the
56
    * formatter. If no adjustments are required, this will simply
57
    * return the vanilla placeholder string.
58
    *  
59
    * @return string
60
    */
61
    public function getPlaceholderText() : string
62
    {
63
        if($this->requiresAdjustment())
64
        {
65
            $text = $this->getAdjustedText();
66
            
67
            return $text;
68
        }
69
        
70
        return $this->location->getPlaceholderString();
71
    }
72
}
73