Session   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromAmazonRequest() 0 8 4
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Request;
6
7
use MaxBeckers\AmazonAlexa\Helper\PropertyHelper;
8
9
class Session
10
{
11
    /**
12
     * @param bool|null $new Whether this is a new session
13
     * @param string|null $sessionId Session identifier
14
     * @param Application|null $application Application information
15
     * @param array $attributes Session attributes
16
     * @param User|null $user User information
17
     */
18 23
    public function __construct(
19
        public ?bool $new = null,
20
        public ?string $sessionId = null,
21
        public ?Application $application = null,
22
        public array $attributes = [],
23
        public ?User $user = null,
24
    ) {
25 23
    }
26
27
    /**
28
     * @param array $amazonRequest
29
     *
30
     * @return Session
31
     */
32 20
    public static function fromAmazonRequest(array $amazonRequest): self
33
    {
34 20
        return new self(
35 20
            new: isset($amazonRequest['new']) ? (bool) $amazonRequest['new'] : null,
36 20
            sessionId: PropertyHelper::checkNullValueString($amazonRequest, 'sessionId'),
37 20
            application: isset($amazonRequest['application']) ? Application::fromAmazonRequest($amazonRequest['application']) : null,
38 20
            attributes: $amazonRequest['attributes'] ?? [],
39 20
            user: isset($amazonRequest['user']) ? User::fromAmazonRequest($amazonRequest['user']) : null,
40 20
        );
41
    }
42
}
43