Completed
Push — master ( d4c7f5...603b58 )
by Roman
06:55
created

Message::setFrom()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace RM\SMSender\EuroSms;
4
5
use Nette\Utils\Strings;
6
use RM\SMSender;
7
use RM\SMSender\InvalidArgumentException;
8
9
/**
10
 * Message for service EuroSms.sk
11
 */
12 1
class Message extends SMSender\Message implements SMSender\IMessage
13
{
14
	/**
15
	 * @param  string $from
16
	 * @return self
17
	 */
18
	public function setFrom($from)
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...
19
	{
20 1
		if (!is_string($from))
21 1
			throw new InvalidArgumentException('Parameter "from" must be type of string, it\'s ' . gettype($from) . '.');
22 1
		if (!Strings::match($from, '~^[0-9a-zA-Z\. -]{1,14}$~'))
23 1
			throw new InvalidArgumentException('Parameter "from" can contain only alphanumerical character, space, "-" and "." and must have from 1-14 characters.');
24 1
		return parent::setFrom($from);
25
	}
26
27
	/**
28
	 * @param  string $number
29
	 * @return self
30
	 */
31
	public function setTo($number)
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...
32
	{
33 1
		if (!is_string($number))
34 1
			throw new InvalidArgumentException('Parameter "number" must be type of string, it\'s ' . gettype($number) . '.');
35 1
		if (!Strings::match($number, '~^09\d{8}|\+?\d{12}$~'))
36 1
			throw new InvalidArgumentException('Parameter "number" can use number in formats "09xxYYYYYY" or "+xxxYYYzzzzzz".');
37 1
		return parent::setTo($number);
38
	}
39
40
	/**
41
	 * @param  string $text
42
	 * @return self
43
	 */
44
	public function setText($text)
45
	{
46 1
		if (!is_string($text))
47 1
			throw new InvalidArgumentException('Parameter "text" must be type of string, it\'s ' . gettype($text) . '.');
48 1
		if (strlen($text) < 1 OR strlen($text) > 160)
49 1
			throw new InvalidArgumentException('Parameter "text" must be length 1-160 characters. Has ' . strlen($text) . ' characters.');
50 1
		return parent::setText(Strings::toAscii($text));
51
	}
52
}
53