Completed
Push — master ( 3b3146...8cb790 )
by Patrick
01:37
created

CertificationEmail   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 87
Duplicated Lines 31.03 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 27
loc 87
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 27 5
A getSubject() 0 4 1
A getBody() 19 36 4
A getHTMLBody() 0 5 1
A getTextBody() 0 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Emails;
3
4
class CertificationEmail extends VolunteerEmail
5
{
6
    protected $text;
7
    protected $additionalProps;
8
9
    public function __construct($profile, $emailTypeSource, $certType, $other = array())
10
    {
11
        parent::__construct($profile);
12
        $dataTable = \DataSetFactory::getDataTableByNames('fvs', 'longText');
13
        $entries = $dataTable->read(new \Data\Filter("id eq $emailTypeSource"));
14
        if(empty($entries))
15
        {
16
            throw new \Exception("Could not locate email with source type $emailTypeSource");
17
        }
18 View Code Duplication
        if(isset($entries['value']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
        {
20
            $this->text = $entries['value'];
21
        }
22
        else if(isset($entries[0]['value']))
23
        {
24
            $this->text = $entries[0]['value'];
25
        }
26
        $this->addToAddress($this->profile->email);
27
        $this->additionalProps = $other;
28
        $dataTable = \DataSetFactory::getDataTableByNames('fvs', 'certifications');
29
        $entries = $dataTable->read(new \Data\Filter("certID eq $certType"));
30
        if(empty($entries))
31
        {
32
            throw new \Exception("Could not locate certification with type $certType");
33
        }
34
        $this->additionalProps['certType'] = $entries[0]['name'];
35
    }
36
37
    public function getSubject()
38
    {
39
        return 'Certification Notification - Burning Flipside Volunteer System';
40
    }
41
42
    protected function getBody($html = true)
43
    {
44
        $firstName = $this->profile->firstName;
45
        $lastName = $this->profile->lastName;
46
        $paperName = $this->profile->getDisplayName('paperName');
47
        $webName = $this->profile->getDisplayName('webName');
48
        $certType = $this->additionalProps['certType'];
49
        $rejectReason = $this->additionalProps['reason'];
50
        $vars = array(
51
          '{$firstName}' => $firstName,
52
          '{$lastName}' => $lastName,
53
          '{$paperName}' => $paperName,
54
          '{$webName}' => $webName,
55
          '{$certType}' => $certType,
56
          '{$rejectReason}' => $rejectReason
57
        );
58 View Code Duplication
        if($html === true)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        {
60
            $text = strtr($this->text, $vars);
61
            return $text;
62
        }
63
        else
64
        {
65
            $rawText = $this->text;
66
            $index = strpos($rawText, "<script");
67
            if($index !== false)
68
            {
69
                $end = strpos($rawText, "</script>");
70
                if($index === 0)
71
                {
72
                    $rawText = substr($rawText, $end+9);
73
                }
74
            }
75
            return strtr(strip_tags($rawText), $vars);
76
        }
77
    }
78
79
    public function getHTMLBody()
80
    {
81
        $body = $this->getBody();
82
        return $body;
83
    }
84
85
    public function getTextBody()
86
    {
87
        $body = $this->getBody(false);
88
        return $body;
89
    }
90
}
91