Passed
Push — master ( fb865f...3ad45c )
by Romain
51s queued 14s
created

HomeUrl::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\ProfileSettings;
6
7
use Kerox\Messenger\Helper\ValidatorTrait;
8
use Kerox\Messenger\Model\Common\Button\WebUrl;
9
10
class HomeUrl implements \JsonSerializable
11
{
12
    use ValidatorTrait;
13
14
    /**
15
     * @var string
16
     */
17
    protected $url;
18
19
    /**
20
     * @var string
21
     */
22
    protected $webviewHeightRation;
23
24
    /**
25
     * @var string
26
     */
27
    protected $webviewShareButton;
28
29
    /**
30
     * @var bool
31
     */
32
    protected $inTest;
33
34
    /**
35
     * HomeUrl constructor.
36
     *
37
     * @throws \Kerox\Messenger\Exception\InvalidUrlException
38
     */
39 1
    public function __construct(
40
        string $url,
41
        string $webviewHeightRation = WebUrl::RATIO_TYPE_TALL,
42
        string $webviewShareButton = 'hide',
43
        bool $inTest = true
44
    ) {
45 1
        $this->isValidUrl($url);
46
47 1
        $this->url = $url;
48 1
        $this->webviewHeightRation = $webviewHeightRation;
49 1
        $this->webviewShareButton = $webviewShareButton;
50 1
        $this->inTest = $inTest;
51 1
    }
52
53
    /**
54
     * @throws \Kerox\Messenger\Exception\InvalidUrlException
55
     *
56
     * @return \Kerox\Messenger\Model\ProfileSettings\HomeUrl
57
     */
58 1
    public static function create(
59
        string $url,
60
        string $webviewHeightRation = WebUrl::RATIO_TYPE_TALL,
61
        string $webviewShareButton = 'hide',
62
        bool $inTest = true
63
    ): self {
64 1
        return new self($url, $webviewHeightRation, $webviewShareButton, $inTest);
65
    }
66
67 1
    public function toArray(): array
68
    {
69
        return [
70 1
            'url' => $this->url,
71 1
            'webview_height_ration' => $this->webviewHeightRation,
72 1
            'webview_share_button' => $this->webviewShareButton,
73 1
            'in_test' => $this->inTest,
74
        ];
75
    }
76
77 1
    public function jsonSerialize(): array
78
    {
79 1
        return $this->toArray();
80
    }
81
}
82