Session::fromAmazonRequest()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 1
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 4
rs 10
c 1
b 0
f 0
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