Completed
Pull Request — master (#38)
by Romain
02:49
created

Greeting::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 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