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

BodyOptions   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 106
Duplicated Lines 14.15 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 3
dl 15
loc 106
ccs 31
cts 31
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getUseTemplate() 0 4 1
A setUseTemplate() 0 5 1
A getContent() 0 4 1
A setContent() 0 5 1
A getCharset() 0 4 1
A setCharset() 0 5 1
A getTemplate() 0 8 2
A setTemplate() 15 15 4

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 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