DeviceInfo   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A jsonSerialize() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoman4eg\Nalog\DTO;
5
6
/**
7
 * @author Artem Dubinin <[email protected]>
8
 */
9
final class DeviceInfo implements \JsonSerializable
10
{
11
    public const SOURCE_TYPE_WEB = 'WEB';
12
    public const APP_VERSION = '1.0.0';
13
    public const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36';
14
15
    private string $type;
16
    private string $deviceId;
17
    private string $appVersion;
18
    private string $userAgent;
19
20
    public function __construct(
21
        string $deviceId,
22
        string $type = self::SOURCE_TYPE_WEB,
23
        string $appVersion = self::APP_VERSION,
24
        string $userAgent = self::USER_AGENT
25
    ) {
26
        $this->type = $type;
27
        $this->deviceId = $deviceId;
28
        $this->appVersion = $appVersion;
29
        $this->userAgent = $userAgent;
30
    }
31
32
    public function jsonSerialize(): array
33
    {
34
        return [
35
            'sourceType' => $this->type,
36
            'sourceDeviceId' => $this->deviceId,
37
            'appVersion' => $this->appVersion,
38
            'metaDetails' => ['userAgent' => $this->userAgent],
39
        ];
40
    }
41
}
42