Completed
Push — master ( edddde...b38748 )
by Hilmi Erdem
01:28
created

ShortMessage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 17.72 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 14
loc 79
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A body() 0 4 1
A hasManyReceivers() 0 4 1
A receivers() 0 4 1
A receiversString() 0 4 1
A toArray() 0 7 1
A toSingleMessageXml() 7 7 1
A toMultipleMessagesXml() 7 7 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
3
namespace Erdemkeren\JetSms;
4
5
/**
6
 * Class ShortMessage.
7
 */
8
class ShortMessage
9
{
10
    /**
11
     * The short message body.
12
     *
13
     * @var string
14
     */
15
    protected $body;
16
17
    /**
18
     * The receivers.
19
     *
20
     * @var array
21
     */
22
    protected $receivers;
23
24
    /**
25
     * ShortMessage constructor.
26
     *
27
     * @param string       $body
28
     * @param string|array $receivers
29
     */
30
    public function __construct($receivers, $body)
31
    {
32
        $this->body = $body;
33
        $this->receivers = is_array($receivers)
34
            ? array_map('trim', $receivers)
35
            : [trim($receivers)];
36
    }
37
38
    public function body()
39
    {
40
        return $this->body;
41
    }
42
43
    public function hasManyReceivers()
44
    {
45
        return count($this->receivers()) > 1;
46
    }
47
48
    public function receivers()
49
    {
50
        return $this->receivers;
51
    }
52
53
    public function receiversString($glue = null)
54
    {
55
        return implode($glue, $this->receivers);
56
    }
57
58
    public function toArray()
59
    {
60
        return array_filter([
61
            'Msisdns'        => $this->receiversString('|'),
62
            'Messages'       => $this->body(),
63
        ]);
64
    }
65
66 View Code Duplication
    public function toSingleMessageXml()
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...
67
    {
68
        $text = str_replace("'", "&apos;", htmlentities($this->body()));
69
        $gsmNo = $this->receiversString(',');
70
71
        return "<text>{$text}</text><message><gsmnos>{$gsmNo}</gsmnos></message>";
72
    }
73
74
    /**
75
     * Get the xml representation of the short message.
76
     *
77
     * @return string
78
     */
79 View Code Duplication
    public function toMultipleMessagesXml()
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...
80
    {
81
        $text = str_replace("'", "&apos;", htmlentities($this->body()));
82
        $gsmNo = $this->receiversString(',');
83
84
        return "<message><gsmno>{$gsmNo}</gsmno><text>{$text}</text></message>";
85
    }
86
}
87