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

ChuanglanGateway   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 47
c 1
b 0
f 0
wmc 3
lcom 0
cbo 6
ccs 0
cts 19
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 19 2
A formatResult() 0 6 1
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 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 \Overtrue\EasySms\Contracts\PhoneNumberInterface $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(PhoneNumberInterface $to, MessageInterface $message, Config $config)
41
    {
42
        $params = [
43
            'un' => $config->get('username'),
44
            'pw' => $config->get('password'),
45
            'phone' => $to->getIDDCode().$to->getNumber(),
46
            'msg' => $message->getContent($this),
47
        ];
48
49
        $result = $this->get(self::ENDPOINT_URL, $params);
50
51
        $formatResult = $this->formatResult($result);
52
53
        if (!empty($formatResult[1])) {
54
            throw new GatewayErrorException($result, $formatResult[1], $formatResult);
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
69
        return explode(',', $result);
70
    }
71
}
72