Passed
Push — master ( fcc86f...3fa4e6 )
by Laurens
01:26
created

Nfc   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A requireAuthentication() 0 3 1
A requiresAuthentication() 0 3 1
A __construct() 0 4 1
A toArray() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\ApplePassbook\MetaData;
6
7
class Nfc
8
{
9
    private string $encryptionPublicKey;
10
    private string $message;
11
    private bool $requiresAuthentication = false;
12
13
    public function __construct(string $encryptionPublicKey, string $message)
14
    {
15
        $this->encryptionPublicKey = $encryptionPublicKey;
16
        $this->message = $message;
17
    }
18
19
    public function requireAuthentication(): void
20
    {
21
        $this->requiresAuthentication = true;
22
    }
23
24
    public function requiresAuthentication(): bool
25
    {
26
        return $this->requiresAuthentication;
27
    }
28
29
    /**
30
     * @return array<string, string|true>
31
     */
32
    public function toArray(): array
33
    {
34
        $data = [
35
            'encryptionPublicKey' => $this->encryptionPublicKey,
36
            'message' => $this->message,
37
        ];
38
39
        if ($this->requiresAuthentication) {
40
            $data['requiresAuthentication'] = $this->requiresAuthentication;
41
        }
42
43
        return $data;
44
    }
45
}
46