Passed
Push — master ( 6c661c...e8275e )
by Sebastian
04:14
created

Mailcode_PreProcessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSafeguard() 0 3 1
A render() 0 8 1
A isValid() 0 3 1
A getValidationResult() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mailcode;
6
7
use AppUtils\OperationResult;
8
9
class Mailcode_PreProcessor
10
{
11
    /**
12
     * @var string
13
     */
14
    private $subject;
15
16
    /**
17
     * @var Mailcode_Parser_Safeguard
18
     */
19
    private $safeguard;
20
21
    /**
22
     * @var string
23
     */
24
    private $safeSubject;
25
26
    public function __construct(string $subject)
27
    {
28
        $this->subject = $subject;
29
        $this->safeguard = Mailcode::create()->createSafeguard($subject);
30
        $this->safeSubject = $this->safeguard->makeSafePartial();
31
    }
32
33
    public function getSafeguard() : Mailcode_Parser_Safeguard
34
    {
35
        return $this->safeguard;
36
    }
37
38
    public function isValid() : bool
39
    {
40
        return $this->safeguard->isValid();
41
    }
42
43
    public function getValidationResult() : OperationResult
44
    {
45
        return $this->safeguard->getCollection()->getValidationResult();
46
    }
47
48
    public function render() : string
49
    {
50
        $formatting = $this->safeguard->createFormatting($this->safeSubject);
51
        $formatting->makePartial();
52
        $formatting->addFormatter($formatting->createPreProcessing());
53
        $formatting->applyFormatting();
54
55
        return $formatting->getSubject()->getString();
56
    }
57
}
58