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.
Completed
Pull Request — master (#42)
by
unknown
03:52
created

ChuanglanGateway::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 15
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 3
crap 6
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 function GuzzleHttp\json_encode;
15
use Overtrue\EasySms\Contracts\MessageInterface;
16
use Overtrue\EasySms\Exceptions\GatewayErrorException;
17
use Overtrue\EasySms\Support\Config;
18
use Overtrue\EasySms\Traits\HasHttpRequest;
19
20
/**
21
 * Class ChuanglanGateway.
22
 *
23
 * @see https://www.253.com/api-docs-1.html
24
 */
25
class ChuanglanGateway extends Gateway
26
{
27
    use HasHttpRequest;
28
29
    const ENDPOINT_URL = 'https://sms.253.com/msg/send';
30
31
    /**
32
     * @param array|int|string                             $to
33
     * @param \Overtrue\EasySms\Contracts\MessageInterface $message
34
     * @param \Overtrue\EasySms\Support\Config             $config
35
     *
36
     * @return array
37
     *
38
     * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException;
39
     */
40
    public function send($to, MessageInterface $message, Config $config)
41
    {
42
        $params = [
43
            'un' => $config->get('un'),
44
            'pw' => $config->get('pw'),
45
            'phone' => $to,
46
            'msg' => $message->getContent(),
47
        ];
48
49
        $result = $this->get(self::ENDPOINT_URL, $params);
50
51
        $formatResult = $this->formatResult($result);
52
53
        if ($formatResult[1]) {
54
            throw new GatewayErrorException($formatResult[3], $formatResult[1], $result);
55
        }
56
57
        return $result;
58
    }
59
60
    /**
61
     * @param $result  http return from 253 service
62
     *
63
     * @return array
64
     */
65
    protected function formatResult($result)
66
    {
67
        $result = str_replace("\n", ',', $result);
68
        return explode(',', $result);
69
    }
70
}
71