PersonaSettings::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model;
6
7
use Kerox\Messenger\Helper\ValidatorTrait;
8
9
class PersonaSettings implements \JsonSerializable
10
{
11
    use ValidatorTrait;
12
13
    /**
14
     * @var string
15
     */
16
    protected $name;
17
18
    /**
19
     * @var string
20
     */
21
    protected $profilePictureUrl;
22
23
    /**
24
     * Persona constructor.
25
     */
26 1
    public function __construct(string $name, string $profilePictureUrl)
27
    {
28 1
        $this->isValidUrl($profilePictureUrl);
29
30 1
        $this->name = $name;
31 1
        $this->profilePictureUrl = $profilePictureUrl;
32 1
    }
33
34
    /**
35
     * @return \Kerox\Messenger\Model\PersonaSettings
36
     */
37 1
    public static function create(string $name, string $profilePictureUrl): self
38
    {
39 1
        return new self($name, $profilePictureUrl);
40
    }
41
42 1
    public function toArray(): array
43
    {
44
        $array = [
45 1
            'name' => $this->name,
46 1
            'profile_picture_url' => $this->profilePictureUrl,
47
        ];
48
49 1
        return array_filter($array);
50
    }
51
52 1
    public function jsonSerialize(): array
53
    {
54 1
        return $this->toArray();
55
    }
56
}
57