GitHubPlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A init() 0 13 1
A graphql() 0 12 1
1
<?php
2
3
namespace Nopolabs\Yabot\Plugins\GitHubV4;
4
5
use Nopolabs\Yabot\Guzzle\Guzzle;
6
use Nopolabs\Yabot\Helpers\GuzzleTrait;
7
use Nopolabs\Yabot\Message\Message;
8
use Nopolabs\Yabot\Plugin\PluginInterface;
9
use Nopolabs\Yabot\Plugin\PluginTrait;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Log\LoggerInterface;
12
13
class GitHubPlugin implements PluginInterface
14
{
15
    use PluginTrait {
16
        init as private traitInit;
17
    }
18
    use GuzzleTrait;
19
20
    public function __construct(
21
        Guzzle $guzzle,
22
        LoggerInterface $logger,
23
        array $config = [])
24
    {
25
        $this->setGuzzle($guzzle);
26
        $this->setLog($logger);
27
        $this->setConfig(array_merge(
28
            [
29
                'matchers' => [
30
                    'graphql' => "/\\bgraphql\\b/i",
31
                ],
32
            ],
33
            $config
34
        ));
35
    }
36
37
    public function init(string $pluginId, array $params)
38
    {
39
        $this->traitInit($pluginId, $params);
40
41
        $token = $this->get('graphql.token');
42
        $options = [
43
            'headers' => [
44
                'Authorization' => "bearer $token",
45
            ],
46
        ];
47
48
        $this->setOptions($options);
49
    }
50
51
    public function graphql(Message $msg, array $matches)
0 ignored issues
show
Unused Code introduced by
The parameter $matches is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        $url = 'https://api.github.com/graphql';
54
55
        $this->postAsync($url, ['body' => '{"query": "query { viewer { login }}"}'])
56
            ->then(
57
                function (ResponseInterface $response) use ($msg) {
58
                    $json = $response->getBody();
59
                    $msg->reply($json);
60
                }
61
            );
62
    }
63
}
64