Messenger::profile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger;
6
7
use GuzzleHttp\Client;
8
use GuzzleHttp\ClientInterface;
9
use Kerox\Messenger\Api\Broadcast;
10
use Kerox\Messenger\Api\Code;
11
use Kerox\Messenger\Api\Insights;
12
use Kerox\Messenger\Api\Nlp;
13
use Kerox\Messenger\Api\Persona;
14
use Kerox\Messenger\Api\Profile;
15
use Kerox\Messenger\Api\Send;
16
use Kerox\Messenger\Api\Tag;
17
use Kerox\Messenger\Api\Thread;
18
use Kerox\Messenger\Api\User;
19
use Kerox\Messenger\Api\Webhook;
20
use Psr\Http\Message\ServerRequestInterface;
21
22
class Messenger
23
{
24
    public const API_URL = 'https://graph.facebook.com/';
25
    public const API_VERSION = 'v5.0';
26
27
    /**
28
     * @var string
29
     */
30
    protected $appSecret;
31
32
    /**
33
     * @var string
34
     */
35
    protected $verifyToken;
36
37
    /**
38
     * @var string
39
     */
40
    protected $pageToken;
41
42
    /**
43
     * @var \GuzzleHttp\ClientInterface
44
     */
45
    protected $client;
46
47
    /**
48
     * Messenger constructor.
49
     */
50 1
    public function __construct(
51
        string $appSecret,
52
        string $verifyToken,
53
        string $pageToken,
54
        string $apiVersion = self::API_VERSION,
55
        ?ClientInterface $client = null
56
    ) {
57 1
        $this->appSecret = $appSecret;
58 1
        $this->verifyToken = $verifyToken;
59 1
        $this->pageToken = $pageToken;
60
61 1
        if ($client === null) {
62 1
            $client = new Client([
63 1
                'base_uri' => self::API_URL . $apiVersion . '/',
64
            ]);
65
        }
66 1
        $this->client = $client;
67 1
    }
68
69 1
    public function send(): Send
70
    {
71 1
        return new Send($this->pageToken, $this->client);
72
    }
73
74 1
    public function webhook(?ServerRequestInterface $request = null): Webhook
75
    {
76 1
        return new Webhook($this->appSecret, $this->verifyToken, $this->pageToken, $this->client, $request);
77
    }
78
79 1
    public function user(): User
80
    {
81 1
        return new User($this->pageToken, $this->client);
82
    }
83
84 1
    public function profile(): Profile
85
    {
86 1
        return new Profile($this->pageToken, $this->client);
87
    }
88
89 1
    public function code(): Code
90
    {
91 1
        return new Code($this->pageToken, $this->client);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Api\Code has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
92
    }
93
94 1
    public function insights(): Insights
95
    {
96 1
        return new Insights($this->pageToken, $this->client);
97
    }
98
99 1
    public function tag(): Tag
100
    {
101 1
        return new Tag($this->pageToken, $this->client);
102
    }
103
104 1
    public function thread(): Thread
105
    {
106 1
        return new Thread($this->pageToken, $this->client);
107
    }
108
109 1
    public function nlp(): Nlp
110
    {
111 1
        return new Nlp($this->pageToken, $this->client);
112
    }
113
114 1
    public function broadcast(): Broadcast
115
    {
116 1
        return new Broadcast($this->pageToken, $this->client);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Api\Broadcast has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
117
    }
118
119 1
    public function persona(): Persona
120
    {
121 1
        return new Persona($this->pageToken, $this->client);
122
    }
123
}
124