Completed
Push — master ( bd46f2...d4c7f5 )
by Roman
08:20
created

Message   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 6.25%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 41
ccs 1
cts 16
cp 0.0625
rs 10
c 0
b 0
f 0

3 Methods

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