Completed
Push — master ( 3b415d...9c7552 )
by Alejandro
02:33
created

BodyOptions::setTemplate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
ccs 11
cts 11
cp 1
rs 9.2
cc 4
eloc 10
nc 3
nop 1
crap 4
1
<?php
2
namespace AcMailer\Options;
3
4
use AcMailer\Service\MailServiceInterface;
5
use Zend\Stdlib\AbstractOptions;
6
use AcMailer\Exception\InvalidArgumentException;
7
8
/**
9
 * Class BodyOptions
10
 * @author Alejandro Celaya Alastrué
11
 * @link http://www.wonnova.com
12
 */
13
class BodyOptions extends AbstractOptions
14
{
15
    /**
16
     * @var bool
17
     */
18
    private $useTemplate = false;
19
    /**
20
     * @var string
21
     */
22
    private $content = '';
23
    /**
24
     * @var string
25
     */
26
    private $charset = MailServiceInterface::DEFAULT_CHARSET;
27
    /**
28
     * @var TemplateOptions
29
     */
30
    private $template;
31
32
    /**
33
     * @return boolean
34
     */
35 12
    public function getUseTemplate()
36
    {
37 12
        return $this->useTemplate;
38
    }
39
40
    /**
41
     * @param boolean $useTemplate
42
     * @return $this
43
     */
44 2
    public function setUseTemplate($useTemplate)
45
    {
46 2
        $this->useTemplate = (bool) $useTemplate;
47 2
        return $this;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 10
    public function getContent()
54
    {
55 10
        return $this->content;
56
    }
57
58
    /**
59
     * @param string $content
60
     * @return $this
61
     */
62 2
    public function setContent($content)
63
    {
64 2
        $this->content = $content;
65 2
        return $this;
66
    }
67
68
    /**
69
     * @return string
70
     */
71 13
    public function getCharset()
72
    {
73 13
        return $this->charset;
74
    }
75
76
    /**
77
     * @param string $charset
78
     * @return $this
79
     */
80 1
    public function setCharset($charset)
81
    {
82 1
        $this->charset = $charset;
83 1
        return $this;
84
    }
85
86
    /**
87
     * @return TemplateOptions
88
     */
89 4
    public function getTemplate()
90
    {
91 4
        if (! isset($this->template)) {
92 1
            $this->setTemplate([]);
93 1
        }
94
95 4
        return $this->template;
96
    }
97
98
    /**
99
     * @param array|TemplateOptions $template
100
     * @return $this
101
     * @throws \AcMailer\Exception\InvalidArgumentException
102
     */
103 5 View Code Duplication
    public function setTemplate($template)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
104
    {
105 5
        if (is_array($template)) {
106 4
            $this->template = new TemplateOptions($template);
107 5
        } elseif ($template instanceof TemplateOptions) {
108 1
            $this->template = $template;
109 1
        } else {
110 1
            throw new InvalidArgumentException(sprintf(
111 1
                'Template should be an array or an AcMailer\Options\TemplateOptions object. %s provided.',
112 1
                is_object($template) ? get_class($template) : gettype($template)
113 1
            ));
114
        }
115
116 4
        return $this;
117
    }
118
}
119