GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( 9d889d...27a869 )
by Carlos
02:09
created

JuheGateway   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 4
lcom 0
cbo 6
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 18 2
A formatTemplateVars() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the overtrue/easy-sms.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\EasySms\Gateways;
13
14
use Overtrue\EasySms\Contracts\MessageInterface;
15
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
16
use Overtrue\EasySms\Exceptions\GatewayErrorException;
17
use Overtrue\EasySms\Support\Config;
18
use Overtrue\EasySms\Traits\HasHttpRequest;
19
20
/**
21
 * Class JuheGateway.
22
 *
23
 * @see https://www.juhe.cn/docs/api/id/54
24
 */
25
class JuheGateway extends Gateway
26
{
27
    use HasHttpRequest;
28
29
    const ENDPOINT_URL = 'http://v.juhe.cn/sms/send';
30
31
    const ENDPOINT_FORMAT = 'json';
32
33
    /**
34
     * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
35
     * @param \Overtrue\EasySms\Contracts\MessageInterface     $message
36
     * @param \Overtrue\EasySms\Support\Config                 $config
37 1
     *
38
     * @return array
39 1
     *
40
     * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ;
41
     */
42
    public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
43
    {
44
        $params = [
45
            'mobile' => $to->getNumber(),
46
            'tpl_id' => $message->getTemplate($this),
47
            'tpl_value' => $this->formatTemplateVars($message->getData($this)),
48
            'dtype' => self::ENDPOINT_FORMAT,
49
            'key' => $config->get('app_key'),
50
        ];
51 1
52
        $result = $this->get(self::ENDPOINT_URL, $params);
53
54 1
        if ($result['error_code']) {
55 1
            throw new GatewayErrorException($result['reason'], $result['error_code'], $result);
56 1
        }
57 1
58 1
        return $result;
59 1
    }
60
61 1
    /**
62
     * @param array $vars
63 1
     *
64 1
     * @return string
65
     */
66
    protected function formatTemplateVars(array $vars)
67 1
    {
68
        $formatted = [];
69
70
        foreach ($vars as $key => $value) {
71
            $formatted[sprintf('#%s#', trim($key, '#'))] = $value;
72
        }
73
74
        return http_build_query($formatted);
75 1
    }
76
}
77