ThreemaGateway_Handler_Action_Abstract   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 101
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getSdk() 0 8 2
A getE2EHelper() 0 4 1
A getThreemaReceiver() 0 11 2
A getCryptTool() 0 4 1
A getConnector() 0 4 1
1
<?php
2
/**
3
 * General purpose action handler.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2015-2016 rugk
8
 * @license MIT
9
 */
10
11
abstract class ThreemaGateway_Handler_Action_Abstract
12
{
13
    /**
14
     * Gateway PHP SDK store.
15
     *
16
     * This variable is private as {@link getSdk()} should be used. This makes
17
     * sure the SDK is only initialized when it is really needed.
18
     *
19
     * @var ThreemaGateway_Handler_PhpSdk
20
     */
21
    private $sdk = null;
22
23
    /**
24
     * @var ThreemaGateway_Handler_Settings
25
     */
26
    protected $settings;
27
28
    /**
29
     * @var ThreemaGateway_Handler_Permissions
30
     */
31
    protected $permissions;
32
33
    /**
34
     * Startup.
35
     */
36
    public function __construct()
37
    {
38
        $this->settings    = new ThreemaGateway_Handler_Settings;
39
        $this->permissions = ThreemaGateway_Handler_Permissions::getInstance();
40
    }
41
42
    /**
43
     * Returns the PHP SDK object.
44
     *
45
     * This is meant for lazy loading the SDK, so it is only loaded when it is
46
     * actually accessed.
47
     *
48
     * @return ThreemaGateway_Handler_PhpSdk
49
     */
50
    protected function getSdk()
51
    {
52
        if ($this->sdk === null) {
53
            $this->sdk = ThreemaGateway_Handler_PhpSdk::getInstance($this->settings);
0 ignored issues
show
Documentation Bug introduced by
It seems like \ThreemaGateway_Handler_...stance($this->settings) can also be of type object<Singleton>. However, the property $sdk is declared as type object<ThreemaGateway_Handler_PhpSdk>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
54
        }
55
56
        return $this->sdk;
57
    }
58
59
    /**
60
     * Returns the PHP SDK E2EHelper.
61
     *
62
     * @return Threema\MsgApi\Helpers\E2EHelper
63
     */
64
    protected function getE2EHelper()
65
    {
66
        return $this->getSdk()->getE2EHelper();
67
    }
68
69
    /**
70
     * Returns the Threema Receiver.
71
     *
72
     * Note that you may need to call $this->getSdk(); manually if you want to
73
     * pass a specific type via the $type param.
74
     *
75
     * @param string $value the query value (Threema ID, phone number, …)
76
     * @param string $type  the type of the queried data (use constzants of Threema\MsgApi\Receiver)
77
     *
78
     * @return Threema\MsgApi\Receiver
79
     */
80
    protected function getThreemaReceiver($value, $type = null)
81
    {
82
        // make sure the SDK is loaded
83
        $this->getSdk();
84
85
        if ($type === null) {
86
            $type = Threema\MsgApi\Receiver::TYPE_ID;
87
        }
88
89
        return new Threema\MsgApi\Receiver($value, $type);
90
    }
91
92
    /**
93
     * Returns the PHP SDK crypt tool.
94
     *
95
     * @return Threema\MsgApi\Tools\CryptTool
96
     */
97
    protected function getCryptTool()
98
    {
99
        return $this->getSdk()->getCryptTool();
100
    }
101
102
    /**
103
     * Returns the PHP SDK connector.
104
     *
105
     * @return Threema\MsgApi\Connection
106
     */
107
    protected function getConnector()
108
    {
109
        return $this->getSdk()->getConnector();
110
    }
111
}
112