• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ringcentral / ringcentral-php / 10243692747

05 Aug 2024 06:22AM UTC coverage: 77.389% (-13.4%) from 90.761%
10243692747

push

github

web-flow
Merge pull request #137 from ringcentral/vendorPatch

Remove PubNub SubscriptionTest

575 of 743 relevant lines covered (77.39%)

7.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/src/SDK.php
1
<?php
2

3
namespace RingCentral\SDK;
4

5
use Exception;
6
use GuzzleHttp\Client as GuzzleClient;
7
use RingCentral\SDK\Http\Client;
8
use RingCentral\SDK\Http\Client as HttpClient;
9
use RingCentral\SDK\Http\MultipartBuilder;
10
use RingCentral\SDK\Platform\Platform;
11
use RingCentral\SDK\Subscription\PubnubSubscription;
12
use RingCentral\SDK\WebSocket\WebSocket;
13
use RingCentral\SDK\WebSocket\Subscription as WebSocketSubscription;
14

15
class SDK
16
{
17

18
    const VERSION = '2.3.6';
19
    const SERVER_PRODUCTION = 'https://platform.ringcentral.com';
20

21
    /** @var Client */
22
    protected $_client;
23

24
    /** @var Platform */
25
    protected $_platform;
26

27
    /** @var WebSocket */
28
    protected $_websocket;
29

30
    /** @var HttpClient */
31
    protected $_guzzle;
32

33
    /**
34
     * SDK constructor.
35
     *
36
     * @param string       $clientId
37
     * @param string       $clientSecret
38
     * @param string       $server
39
     * @param string       $appName
40
     * @param string       $appVersion
41
     * @param GuzzleClient $guzzle
42
     */
43
    public function __construct(
44
        $clientId,
45
        $clientSecret,
46
        $server,
47
        $appName = '',
48
        $appVersion = '',
49
        $guzzle = null
50
    ) {
51

52
        $pattern = "/[^a-z0-9-_.]/i";
25✔
53

54
        $appName = preg_replace($pattern, '', $appName);
25✔
55
        $appVersion = preg_replace($pattern, '', $appVersion);
25✔
56

57
        $this->_guzzle = $guzzle ? $guzzle : new GuzzleClient();
25✔
58

59
        $this->_client = new Client($this->_guzzle);
25✔
60

61
        $this->_platform = new Platform($this->_client, $clientId, $clientSecret, $server, $appName, $appVersion);
25✔
62

63
    }
64

65
    /**
66
     * @return Platform
67
     */
68
    public function platform()
69
    {
70
        return $this->_platform;
24✔
71
    }
72

73
    /**
74
     * @return PubnubSubscription | WebSocketSubscription
75
     */
76
    public function createSubscription(string $type = 'WebSocket')
77
    {
78
        if ($type == 'Pubnub') {
5✔
79
            trigger_error(
×
80
                'PubNub support is deprecated. Please migrate your application to WebSockets.',
×
81
                E_USER_DEPRECATED
×
82
            );
×
83
            return new PubnubSubscription($this->_platform);
×
84
        }
85
        if (empty($this->websocket())) {
5✔
86
            throw new Exception('WebSocket is not initialized');
1✔
87
        }
88
        return new WebSocketSubscription($this->platform(), $this->websocket());
4✔
89
    }
90

91
    /**
92
     * @return MultipartBuilder
93
     */
94
    public function createMultipartBuilder()
95
    {
96
        return new MultipartBuilder();
1✔
97
    }
98

99
    /**
100
     * @return WebSocket
101
     */
102
    public function initWebSocket()
103
    {
104
        if (!$this->_websocket) {
10✔
105
            $this->_websocket = new WebSocket($this->_platform);
10✔
106
        }
107
        return $this->_websocket;
10✔
108
    }
109

110
    public function disconnectWebSocket()
111
    {
112
        if ($this->_websocket) {
1✔
113
            $this->_websocket->close();
1✔
114
        }
115
        $this->_websocket = null;
1✔
116
    }
117

118
    public function websocket()
119
    {
120
        return $this->_websocket;
7✔
121
    }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc