Completed
Push — master ( 5c498e...edddde )
by Hilmi Erdem
01:29
created

ShortMessage::receivers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 6
    public function __construct($receivers, $body)
31
    {
32 6
        $this->body = $body;
33 6
        $this->receivers = is_array($receivers)
34 6
            ? array_map('trim', $receivers)
35 6
            : [trim($receivers)];
36 6
    }
37
38 6
    public function body()
39
    {
40 6
        return $this->body;
41
    }
42
43 1
    public function hasManyReceivers()
44
    {
45 1
        return count($this->receivers()) > 1;
46
    }
47
48 2
    public function receivers()
49
    {
50 2
        return $this->receivers;
51
    }
52
53 6
    public function receiversString($glue = null)
54
    {
55 6
        return implode($glue, $this->receivers);
56
    }
57
58 1
    public function toArray()
59
    {
60 1
        return array_filter([
61 1
            'Msisdns'        => $this->receiversString('|'),
62 1
            'Messages'       => $this->body(),
63 1
        ]);
64
    }
65
66 1 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 1
        $text = str_replace("'", "&apos;", htmlentities($this->body()));
69 1
        $gsmNo = $this->receiversString(',');
70
71 1
        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 1 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 1
        $text = str_replace("'", "&apos;", htmlentities($this->body()));
82 1
        $gsmNo = $this->receiversString(',');
83
84 1
        return "<message><gsmno>{$gsmNo}</gsmno><text>{$text}</text></message>";
85
    }
86
}
87