Skip to content

Commit 3d5ca3b

Browse files
committed
Update misc. docs, types, names, visibility
1 parent c2fe18c commit 3d5ca3b

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

lib/Connection.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public function isReady(): bool {
6565
return $this->processor->isReady();
6666
}
6767

68-
public function forceClose() {
69-
$this->processor->closeSocket();
68+
protected function forceClose() {
69+
$this->processor->close();
7070
}
7171

72-
public function getConfig() {
72+
public function getConfig(): ConnectionConfig {
7373
return clone $this->processor->config;
7474
}
7575

@@ -97,7 +97,7 @@ public function close() {
9797
$processor->sendPacket("\x01");
9898
$processor->initClosing();
9999
})->onResolve(static function() use ($processor) {
100-
$processor->closeSocket();
100+
$processor->close();
101101
});
102102
}
103103

lib/DataTypes.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function encodeBinary($param): array {
8282
$value = "";
8383
break;
8484
default:
85-
throw new \UnexpectedValueException("Unexpected type for binding parameter: " . gettype($param));
85+
throw new FailureException("Unexpected type for binding parameter: " . gettype($param));
8686
}
8787

8888
return [$unsigned, $type, $value];
@@ -159,7 +159,7 @@ public static function decodeBinary(int $type, string $str, /* ?int */ &$len = 0
159159
break;
160160

161161
default:
162-
throw new \UnexpectedValueException("Unexpected string length for date in binary protocol: " . ($len - 1));
162+
throw new FailureException("Unexpected string length for date in binary protocol: " . ($len - 1));
163163
}
164164
return str_pad($year, 2, "0", STR_PAD_LEFT) . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT) . " " . str_pad($hour, 2, "0", STR_PAD_LEFT) . ":" . str_pad($minute, 2, "0", STR_PAD_LEFT) . ":" . str_pad($second, 2, "0", STR_PAD_LEFT) . "." . str_pad($microsecond, 5, "0", STR_PAD_LEFT);
165165

@@ -178,7 +178,7 @@ public static function decodeBinary(int $type, string $str, /* ?int */ &$len = 0
178178
break;
179179

180180
default:
181-
throw new \UnexpectedValueException("Unexpected string length for time in binary protocol: " . ($len - 1));
181+
throw new FailureException("Unexpected string length for time in binary protocol: " . ($len - 1));
182182
}
183183
return ($negative ? "" : "-") . str_pad($day, 2, "0", STR_PAD_LEFT) . "d " . str_pad($hour, 2, "0", STR_PAD_LEFT) . ":" . str_pad($minute, 2, "0", STR_PAD_LEFT) . ":" . str_pad($second, 2, "0", STR_PAD_LEFT) . "." . str_pad($microsecond, 5, "0", STR_PAD_LEFT);
184184

@@ -187,7 +187,7 @@ public static function decodeBinary(int $type, string $str, /* ?int */ &$len = 0
187187
return null;
188188

189189
default:
190-
throw new \UnexpectedValueException("Invalid type for Binary Protocol: 0x" . dechex($type));
190+
throw new FailureException("Invalid type for Binary Protocol: 0x" . dechex($type));
191191
}
192192
}
193193

@@ -217,7 +217,7 @@ public static function decodeUnsignedOff(string $str, int &$off): int {
217217
return self::decode_unsigned64(substr($str, $off - 8, 8));
218218
} else {
219219
// If that happens connection is borked...
220-
throw new \RangeException("$int is not in ranges [0x00, 0xfa] or [0xfc, 0xfe]");
220+
throw new FailureException("$int is not in ranges [0x00, 0xfa] or [0xfc, 0xfe]");
221221
}
222222
}
223223

@@ -242,7 +242,7 @@ public static function decodeUnsigned(string $str, /* ?int */ &$len = 0): int {
242242
return self::decode_unsigned64(substr($str, 1, 8));
243243
} else {
244244
// If that happens connection is borked...
245-
throw new \RangeException("$int is not in ranges [0x00, 0xfa] or [0xfc, 0xfe]");
245+
throw new FailureException("$int is not in ranges [0x00, 0xfa] or [0xfc, 0xfe]");
246246
}
247247
}
248248

@@ -343,7 +343,7 @@ public static function encodeInt(int $int): string {
343343
} elseif ($int < (1 << 62) * 4) {
344344
return "\xfe" . self::encode_int64($int);
345345
} else {
346-
throw new \OutOfRangeException("encodeInt doesn't allow integers bigger than 2^64 - 1 (current: $int)");
346+
throw new FailureException("encodeInt doesn't allow integers bigger than 2^64 - 1 (current: $int)");
347347
}
348348
}
349349

lib/Internal/Processor.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class Processor {
5050
/** @var \Generator[] */
5151
private $processors = [];
5252

53+
/** @var int */
5354
private $protocol;
55+
5456
private $seqId = -1;
5557
private $compressionId = -1;
5658

@@ -60,11 +62,13 @@ class Processor {
6062
private $authPluginDataLen;
6163
private $query;
6264
public $named = [];
65+
6366
/** @var callable|null */
6467
private $parseCallback = null;
6568
/** @var callable|null */
6669
private $packetCallback = null;
6770

71+
/** @var \Amp\Promise|null */
6872
private $pendingWrite;
6973

7074
/** @var \Amp\Mysql\ConnectionConfig */
@@ -139,15 +143,11 @@ public function isReady(): bool {
139143
public function delRef() {
140144
if (!--$this->refcount) {
141145
$this->appendTask(function() {
142-
$this->closeSocket();
146+
$this->close();
143147
});
144148
}
145149
}
146150

147-
public function forceClose() {
148-
$this->closeSocket();
149-
}
150-
151151
private function ready() {
152152
if (empty($this->deferreds)) {
153153
if (empty($this->onReady)) {
@@ -445,7 +445,7 @@ private function handleError($packet) {
445445
$this->ready();
446446
} elseif ($this->connectionState < self::READY) {
447447
// connection failure
448-
$this->closeSocket();
448+
$this->close();
449449
$this->getDeferred()->fail(new InitializationException("Could not connect to {$this->config->resolvedHost}: {$this->connInfo->errorState} {$this->connInfo->errorMsg}"));
450450
}
451451
}
@@ -886,7 +886,7 @@ public function initClosing() {
886886
$this->connectionState = self::CLOSING;
887887
}
888888

889-
public function closeSocket() {
889+
public function close() {
890890
$this->connectionState = self::CLOSED;
891891
if ($this->socket) {
892892
$this->socket->close();
@@ -980,7 +980,7 @@ private function goneAway() {
980980
$deferred->fail(new ConnectionException("Connection went away... unable to fulfil this deferred ... It's unknown whether the query was executed...", $this->query));
981981
}
982982
}
983-
$this->closeSocket();
983+
$this->close();
984984
}
985985

986986
/** @see 14.4 Compression */
@@ -1184,7 +1184,7 @@ private function sendHandshake($inSSL = false) {
11841184

11851185
$this->sendHandshake(true);
11861186
} catch (\Throwable $e) {
1187-
$this->closeSocket();
1187+
$this->close();
11881188
$this->getDeferred()->fail($e);
11891189
}
11901190
});

lib/Internal/ResultProxy.php

+6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ class ResultProxy {
1010
public $rows = [];
1111
public $fetchedRows = 0;
1212
public $userFetched = 0;
13+
14+
/** @var \Amp\Deferred[][] */
1315
public $deferreds = [self::SINGLE_ROW_FETCH => [], self::COLUMNS_FETCHED => [], self::ROWS_FETCHED => []];
16+
17+
/** @var int */
1418
public $state = self::UNFETCHED;
19+
20+
/** @var \Amp\Deferred|null */
1521
public $next;
1622

1723
const UNFETCHED = 0;

lib/ResultSet.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public function onComplete(callable $onComplete) {
7474

7575
/**
7676
* {@inheritdoc}
77+
*
78+
* @param int $type Result fetch type. Use the FETCH_* constant defined by this class.
7779
*/
7880
public function advance(int $type = self::FETCH_ASSOC): Promise {
7981
$this->currentRow = null;
@@ -137,7 +139,7 @@ private static function getNextResultSet(Internal\ResultProxy $result): Promise
137139
}
138140

139141
/**
140-
* @return \Amp\Promise<string[]>
142+
* @return \Amp\Promise<mixed[][]>
141143
*/
142144
public function getFields(): Promise {
143145
if ($this->result->state >= Internal\ResultProxy::COLUMNS_FETCHED) {

lib/Statement.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(Internal\Processor $processor, string $query, int $s
4646

4747
private function getProcessor(): Internal\Processor {
4848
if (!$this->processor->isAlive()) {
49-
throw new ConnectionException("Connection went away, no way provided to restore connection via callable in ConnectionConfig::ready");
49+
throw new ConnectionException("Connection went away");
5050
}
5151

5252
return $this->processor;
@@ -64,17 +64,19 @@ public function onComplete(callable $onComplete) {
6464
* @throws \TypeError
6565
*/
6666
public function bind($paramId, $data) {
67-
if (is_numeric($paramId)) {
67+
if (is_int($paramId)) {
6868
if ($paramId >= $this->numParamCount) {
6969
throw new \Error("Parameter id $paramId is not defined for this prepared statement");
7070
}
7171
$i = $paramId;
72-
} else {
72+
} elseif (is_string($paramId)) {
7373
if (!isset($this->byNamed[$paramId])) {
7474
throw new \Error("Parameter :$paramId is not defined for this prepared statement");
7575
}
7676
$array = $this->byNamed[$paramId];
7777
$i = reset($array);
78+
} else {
79+
throw new \TypeError("Invalid parameter ID type");
7880
}
7981

8082
if (!is_scalar($data) && !(is_object($data) && method_exists($data, '__toString'))) {

0 commit comments

Comments
 (0)