Passed
Push — master ( da3f2a...c03036 )
by Shahrad
01:59
created

SocketClient::setConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace EasyHttp;
4
5
use EasyHttp\Contracts\CommonsContract;
6
use EasyHttp\Contracts\MessageContract;
7
use EasyHttp\Contracts\WebSocketContract;
8
9
/**
10
 * SocketClient class
11
 *
12
 * @method void send($payload, string $opcode = CommonsContract::EVENT_TYPE_TEXT)
13
 * @method bool|null|string close(int $status = 1000, string $message = 'ttfn')
14
 * @method void onOpen()
15
 *
16
 * @link    https://github.com/shahradelahi/easy-http
17
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
18
 * @license https://github.com/shahradelahi/easy-http/blob/master/LICENSE (MIT License)
19
 */
20
abstract class SocketClient implements WebSocketContract, MessageContract
21
{
22
23
	/**
24
	 * @var WebSocket
25
	 */
26
	protected WebSocket $websocket;
27
28
	/**
29
	 * @param WebSocket $websocket
30
	 * @return void
31
	 */
32
	protected function setConnection(WebSocket $websocket): void
33
	{
34
		$this->websocket = $websocket;
35
	}
36
37
	/**
38
	 * @param string $name
39
	 * @param array $arguments
40
	 * @return mixed
41
	 */
42
	public function __call(string $name, array $arguments): mixed
43
	{
44
		if (method_exists($this, $name)) {
45
			return call_user_func_array([$this, $name], $arguments);
46
		}
47
48
		if (method_exists($this->websocket, $name)) {
49
			return call_user_func_array([$this->websocket, $name], $arguments);
50
		}
51
52
		throw new \BadMethodCallException(sprintf(
53
			'Method `%s` does not exist at `%s`', $name, get_class($this)
54
		));
55
	}
56
57
}
58