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

Mailcode_PreProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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