Passed
Push — master ( 195aeb...469104 )
by Romain
36s
created

Greeting   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A jsonSerialize() 0 9 1
1
<?php
2
namespace Kerox\Messenger\Model\ProfileSettings;
3
4
use Kerox\Messenger\Helper\ValidatorTrait;
5
6
class Greeting implements ProfileSettingsInterface, \JsonSerializable
7
{
8
9
    use ValidatorTrait;
10
11
    /**
12
     * @var string
13
     */
14
    protected $text;
15
16
    /**
17
     * @var string
18
     */
19
    protected $locale;
20
21
    /**
22
     * Greeting constructor.
23
     *
24
     * @param string $text
25
     * @param string $locale
26
     */
27 2
    public function __construct(string $text, string $locale = self::DEFAULT_LOCALE)
28
    {
29 2
        $this->isValidString($text, 160);
30
31 2
        if ($locale !== self::DEFAULT_LOCALE) {
32 1
            $this->isValidLocale($locale);
33
        }
34
35 2
        $this->text = $text;
36 2
        $this->locale = $locale;
37 2
    }
38
39
    /**
40
     * @return array
41
     */
42 2
    public function jsonSerialize(): array
43
    {
44
        $json = [
45 2
            'locale' => $this->locale,
46 2
            'text' => $this->text,
47
        ];
48
49 2
        return $json;
50
    }
51
}
52