ThreemaGateway_Handler_DbKeystore::savePublicKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * Splits keystore requests to model and DataWriter.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2015-2016 rugk
8
 * @license MIT
9
 */
10
11
/**
12
 * Initiates a real SDK keystore, but only redirects requests.
13
 */
14
class ThreemaGateway_Handler_DbKeystore extends Threema\MsgApi\PublicKeyStore
15
{
16
    /**
17
     * @var ThreemaGateway_Model_Keystore Model to keystore
18
     */
19
    private $model;
20
21
    /**
22
     * @var ThreemaGateway_DataWriter_Keystore DataWriter of keystore
23
     */
24
    private $dataWriter;
25
26
    /**
27
     * Initialises the key store.
28
     *
29
     * @return PhpFile
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
     */
31
    public function __construct()
32
    {
33
        $this->model      = XenForo_Model::create('ThreemaGateway_Model_Keystore');
34
        $this->dataWriter = XenForo_DataWriter::create('ThreemaGateway_DataWriter_Keystore');
35
    }
36
37
    /**
38
     * Find public key. Returns null if the public key not found in the store.
39
     *
40
     * @param  string      $threemaId
41
     * @return null|string
42
     */
43
    public function findPublicKey($threemaId)
44
    {
45
        return $this->model->findPublicKey($threemaId);
46
    }
47
48
    /**
49
     * Save a public key.
50
     *
51
     * @param  string $threemaId
52
     * @param  string $publicKey
53
     * @return bool
54
     */
55
    public function savePublicKey($threemaId, $publicKey)
56
    {
57
        $this->dataWriter->set('threema_id', $threemaId);
58
        $this->dataWriter->set('public_key', $publicKey);
59
        return $this->dataWriter->save();
60
    }
61
62
    /**
63
     * Ignores requests to create method.
64
     *
65
     * @param string $path
66
     */
67
    public static function create($path)
68
    {
69
        return;
70
    }
71
}
72