Completed
Pull Request — master (#3)
by Romain
01:42
created

Messenger   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 103
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A send() 0 8 2
A webhook() 0 8 2
A user() 0 8 2
A thread() 0 8 2
1
<?php
2
namespace Kerox\Messenger;
3
4
use Kerox\Messenger\Api\Send;
5
use Kerox\Messenger\Api\Thread;
6
use Kerox\Messenger\Api\User;
7
use Kerox\Messenger\Api\Webhook;
8
9
class Messenger
10
{
11
12
    const API_URL = 'https://graph.facebook.com/';
13
    const API_VERSION = 'v2.6';
14
15
    /**
16
     * @var string
17
     */
18
    protected $appSecret;
19
20
    /**
21
     * @var string
22
     */
23
    protected $verifyToken;
24
25
    /**
26
     * @var string
27
     */
28
    protected $pageToken;
29
30
    /**
31
     * @var \Kerox\Messenger\Api\Send
32
     */
33
    protected $sendApi;
34
35
    /**
36
     * @var \Kerox\Messenger\Api\Webhook
37
     */
38
    protected $webhookApi;
39
40
    /**
41
     * @var \Kerox\Messenger\Api\User
42
     */
43
    protected $userApi;
44
45
    /**
46
     * @var \Kerox\Messenger\Api\Thread
47
     */
48
    protected $threadApi;
49
50
    /**
51
     * Messenger constructor.
52
     *
53
     * @param string $appSecret
54
     * @param string $verifyToken
55
     * @param string $pageToken
56
     */
57
    public function __construct(string $appSecret, string $verifyToken, string $pageToken)
58
    {
59
        $this->appSecret = $appSecret;
60
        $this->verifyToken = $verifyToken;
61
        $this->pageToken = $pageToken;
62
    }
63
64
    /**
65
     * @return \Kerox\Messenger\Api\Send
66
     */
67
    public function send(): Send
68
    {
69
        if ($this->sendApi === null) {
70
            $this->sendApi = new Send($this->pageToken);
71
        }
72
73
        return $this->sendApi;
74
    }
75
76
    /**
77
     * @return \Kerox\Messenger\Api\Webhook
78
     */
79
    public function webhook(): Webhook
80
    {
81
        if ($this->webhookApi === null) {
82
            $this->webhookApi = new Webhook($this->appSecret, $this->verifyToken, $this->pageToken);
83
        }
84
85
        return $this->webhookApi;
86
    }
87
88
    /**
89
     * @return \Kerox\Messenger\Api\User
90
     */
91
    public function user(): User
92
    {
93
        if ($this->userApi === null) {
94
            $this->userApi = new User($this->pageToken);
95
        }
96
97
        return $this->userApi;
98
    }
99
100
    /**
101
     * @return \Kerox\Messenger\Api\Thread
102
     */
103
    public function thread(): Thread
104
    {
105
        if ($this->threadApi === null) {
106
            $this->threadApi = new Thread($this->pageToken);
107
        }
108
109
        return $this->threadApi;
110
    }
111
}
112