Passed
Push — master ( 3583a4...4f8d46 )
by Romain
35s queued 10s
created

PersonaSettings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
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
     * @param string $name
27
     * @param string $profilePictureUrl
28
     */
29 1
    public function __construct(string $name, string $profilePictureUrl)
30
    {
31 1
        $this->isValidUrl($profilePictureUrl);
32
33 1
        $this->name = $name;
34 1
        $this->profilePictureUrl = $profilePictureUrl;
35 1
    }
36
37
    /**
38
     * @param string $name
39
     * @param string $profilePictureUrl
40
     *
41
     * @return \Kerox\Messenger\Model\PersonaSettings
42
     */
43 1
    public static function create(string $name, string $profilePictureUrl): self
44
    {
45 1
        return new self($name, $profilePictureUrl);
46
    }
47
48
    /**
49
     * @return array
50
     */
51 1
    public function toArray(): array
52
    {
53
        $array = [
54 1
            'name' => $this->name,
55 1
            'profile_picture_url' => $this->profilePictureUrl,
56
        ];
57
58 1
        return array_filter($array);
59
    }
60
61
    /**
62
     * @return array
63
     */
64 1
    public function jsonSerialize(): array
65
    {
66 1
        return $this->toArray();
67
    }
68
}
69