Issues (1358)

modules/WebSockets/Pool.php (4 issues)

Labels
Severity
1
<?php
2
/**
3
 * @package    WebSockets
4
 * @subpackage CleverStyle Framework We
5
 * @author     Nazar Mokrynskyi <[email protected]>
6
 * @license    0BSD
7
 */
8
namespace cs\modules\WebSockets;
9
use
10
	cs\Config,
11
	cs\DB\Accessor,
12
	cs\Singleton;
13
14
/**
15
 * @method static $this instance($check = false)
16
 */
17
class Pool {
18
	use
19
		Accessor,
20
		Singleton;
21
	/**
22
	 * @inheritdoc
23
	 */
24
	protected function cdb () {
25
		return Config::instance()->module('WebSockets')->db('pool');
26
	}
27
	/**
28
	 * Get addresses of all servers
29
	 *
30
	 * @return string[]
31
	 */
32
	public function get_all () {
33
		return $this->db_prime()->qfas(
34
			'SELECT `address`
0 ignored issues
show
'SELECT `address` FRO... ORDER BY `date` ASC' of type string is incompatible with the type string[] expected by parameter $query of cs\DB\_Abstract::qfas(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
			/** @scrutinizer ignore-type */ 'SELECT `address`
Loading history...
35
			FROM `[prefix]websockets_pool`
36
			ORDER BY `date` ASC'
37
		) ?: [];
38
	}
39
	/**
40
	 * Get master server address
41
	 *
42
	 * @return false|string
43
	 */
44
	public function get_master () {
45
		$servers = $this->get_all();
46
		return $servers ? $servers[0] : false;
47
	}
48
	/**
49
	 * Add server with specified address to server
50
	 *
51
	 * @param string $server_address Address of WebSockets server in format wss://server/WebSockets or ws://server/WebSockets
52
	 *
53
	 * @return bool
54
	 */
55
	public function add ($server_address) {
56
		return (bool)$this->db_prime()->q(
57
			"INSERT IGNORE INTO `[prefix]websockets_pool`
58
			(
59
				`date`,
60
				`address`
61
			) VALUES (
62
				'%s',
63
				'%s'
64
			)",
65
			time(),
0 ignored issues
show
time() of type integer is incompatible with the type array expected by parameter $parameters of cs\DB\_Abstract::q(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
			/** @scrutinizer ignore-type */ time(),
Loading history...
66
			$server_address
0 ignored issues
show
$server_address of type string is incompatible with the type array expected by parameter $parameters of cs\DB\_Abstract::q(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
			/** @scrutinizer ignore-type */ $server_address
Loading history...
67
		);
68
	}
69
	/**
70
	 * Delete server with specified address from pool
71
	 *
72
	 * @param string $server_address
73
	 *
74
	 * @return bool
75
	 *
76
	 */
77
	public function del ($server_address) {
78
		return (bool)$this->db_prime()->q(
79
			"DELETE FROM `[prefix]websockets_pool`
80
			WHERE `address` = '%s'",
81
			$server_address
0 ignored issues
show
$server_address of type string is incompatible with the type array expected by parameter $parameters of cs\DB\_Abstract::q(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
			/** @scrutinizer ignore-type */ $server_address
Loading history...
82
		);
83
	}
84
}
85