Skip to content

Commit a40cdd5

Browse files
committed
Declare tentative return types for ext/sqlite3
Closes GH-7000
1 parent 37a3c9b commit a40cdd5

File tree

3 files changed

+126
-111
lines changed

3 files changed

+126
-111
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ PHP_METHOD(SQLite3, query)
566566
php_sqlite3_error(db_obj, "%s", errtext);
567567
sqlite3_free(errtext);
568568
}
569-
return;
569+
RETURN_FALSE;
570570
}
571571

572572
object_init_ex(&stmt, php_sqlite3_stmt_entry);
@@ -680,7 +680,7 @@ PHP_METHOD(SQLite3, querySingle)
680680
php_sqlite3_error(db_obj, "%s", errtext);
681681
sqlite3_free(errtext);
682682
}
683-
return;
683+
RETURN_FALSE;
684684
}
685685

686686
return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &stmt, NULL);
@@ -1955,7 +1955,7 @@ PHP_METHOD(SQLite3Result, fetchArray)
19551955
case SQLITE_ROW:
19561956
/* If there was no return value then just skip fetching */
19571957
if (!USED_RET()) {
1958-
return;
1958+
RETURN_FALSE;
19591959
}
19601960

19611961
array_init(return_value);

ext/sqlite3/sqlite3.stub.php

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -10,131 +10,131 @@ class SQLite3
1010
*/
1111
public function __construct(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = "") {}
1212

13-
/** @return void */
14-
public function open(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = "") {}
13+
/** @tentative-return-type */
14+
public function open(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = ""): void {}
1515

1616
/** @return bool */
17-
public function close() {}
17+
public function close() {} // TODO make return type void
1818

19-
/** @return array */
20-
public static function version() {}
19+
/** @tentative-return-type */
20+
public static function version(): array {}
2121

22-
/** @return int */
23-
public function lastInsertRowID() {}
22+
/** @tentative-return-type */
23+
public function lastInsertRowID(): int {}
2424

25-
/** @return int */
26-
public function lastErrorCode() {}
25+
/** @tentative-return-type */
26+
public function lastErrorCode(): int {}
2727

28-
/** @return int */
29-
public function lastExtendedErrorCode() {}
28+
/** @tentative-return-type */
29+
public function lastExtendedErrorCode(): int {}
3030

31-
/** @return string */
32-
public function lastErrorMsg() {}
31+
/** @tentative-return-type */
32+
public function lastErrorMsg(): string {}
3333

34-
/** @return int */
35-
public function changes() {}
34+
/** @tentative-return-type */
35+
public function changes(): int {}
3636

37-
/** @return bool */
38-
public function busyTimeout(int $milliseconds) {}
37+
/** @tentative-return-type */
38+
public function busyTimeout(int $milliseconds): bool {}
3939

4040
#ifndef SQLITE_OMIT_LOAD_EXTENSION
41-
/** @return bool */
42-
public function loadExtension(string $name) {}
41+
/** @tentative-return-type */
42+
public function loadExtension(string $name): bool {}
4343
#endif
4444

4545
#if SQLITE_VERSION_NUMBER >= 3006011
46-
/** @return bool */
47-
public function backup(SQLite3 $destination, string $sourceDatabase = "main", string $destinationDatabase = "main") {}
46+
/** @tentative-return-type */
47+
public function backup(SQLite3 $destination, string $sourceDatabase = "main", string $destinationDatabase = "main"): bool {}
4848
#endif
4949

50-
/** @return string */
51-
public static function escapeString(string $string) {}
50+
/** @tentative-return-type */
51+
public static function escapeString(string $string): string {}
5252

53-
/** @return SQLite3Stmt|false */
54-
public function prepare(string $query) {}
53+
/** @tentative-return-type */
54+
public function prepare(string $query): SQLite3Stmt|false {}
5555

56-
/** @return bool */
57-
public function exec(string $query) {}
56+
/** @tentative-return-type */
57+
public function exec(string $query): bool {}
5858

59-
/** @return SQLite3Result|false */
60-
public function query(string $query) {}
59+
/** @tentative-return-type */
60+
public function query(string $query): SQLite3Result|false {}
6161

62-
/** @return mixed */
63-
public function querySingle(string $query, bool $entireRow = false) {}
62+
/** @tentative-return-type */
63+
public function querySingle(string $query, bool $entireRow = false): mixed {}
6464

65-
/** @return bool */
66-
public function createFunction(string $name, callable $callback, int $argCount = -1, int $flags = 0) {}
65+
/** @tentative-return-type */
66+
public function createFunction(string $name, callable $callback, int $argCount = -1, int $flags = 0): bool {}
6767

68-
/** @return bool */
69-
public function createAggregate(string $name, callable $stepCallback, callable $finalCallback, int $argCount = -1) {}
68+
/** @tentative-return-type */
69+
public function createAggregate(string $name, callable $stepCallback, callable $finalCallback, int $argCount = -1): bool {}
7070

71-
/** @return bool */
72-
public function createCollation(string $name, callable $callback) {}
71+
/** @tentative-return-type */
72+
public function createCollation(string $name, callable $callback): bool {}
7373

7474
/** @return resource|false */
7575
public function openBlob(string $table, string $column, int $rowid, string $database = "main", int $flags = SQLITE3_OPEN_READONLY) {}
7676

77-
/** @return bool */
78-
public function enableExceptions(bool $enable = false) {}
77+
/** @tentative-return-type */
78+
public function enableExceptions(bool $enable = false): bool {}
7979

80-
/** @return bool */
81-
public function enableExtendedResultCodes(bool $enable = true) {}
80+
/** @tentative-return-type */
81+
public function enableExtendedResultCodes(bool $enable = true): bool {}
8282

83-
/** @return bool */
84-
public function setAuthorizer(?callable $callback) {}
83+
/** @tentative-return-type */
84+
public function setAuthorizer(?callable $callback): bool {}
8585
}
8686

8787
class SQLite3Stmt
8888
{
8989
private function __construct(SQLite3 $sqlite3, string $query) {}
9090

91-
/** @return bool */
92-
public function bindParam(string|int $param, mixed &$var, int $type = SQLITE3_TEXT) {}
91+
/** @tentative-return-type */
92+
public function bindParam(string|int $param, mixed &$var, int $type = SQLITE3_TEXT): bool {}
9393

94-
/** @return bool */
95-
public function bindValue(string|int $param, mixed $value, int $type = SQLITE3_TEXT) {}
94+
/** @tentative-return-type */
95+
public function bindValue(string|int $param, mixed $value, int $type = SQLITE3_TEXT): bool {}
9696

97-
/** @return bool */
98-
public function clear() {}
97+
/** @tentative-return-type */
98+
public function clear(): bool {}
9999

100-
/** @return bool */
101-
public function close() {}
100+
/** @tentative-return-type */
101+
public function close(): bool {}
102102

103-
/** @return SQLite3Result|false */
104-
public function execute() {}
103+
/** @tentative-return-type */
104+
public function execute(): SQLite3Result|false {}
105105

106-
/** @return string|false */
107-
public function getSQL(bool $expand = false) {}
106+
/** @tentative-return-type */
107+
public function getSQL(bool $expand = false): string|false {}
108108

109-
/** @return int */
110-
public function paramCount() {}
109+
/** @tentative-return-type */
110+
public function paramCount(): int {}
111111

112-
/** @return bool */
113-
public function readOnly() {}
112+
/** @tentative-return-type */
113+
public function readOnly(): bool {}
114114

115-
/** @return bool */
116-
public function reset() {}
115+
/** @tentative-return-type */
116+
public function reset(): bool {}
117117
}
118118

119119
class SQLite3Result
120120
{
121121
private function __construct() {}
122122

123-
/** @return int */
124-
public function numColumns() {}
123+
/** @tentative-return-type */
124+
public function numColumns(): int {}
125125

126-
/** @return string|false */
127-
public function columnName(int $column) {}
126+
/** @tentative-return-type */
127+
public function columnName(int $column): string|false {}
128128

129-
/** @return int|false */
130-
public function columnType(int $column) {}
129+
/** @tentative-return-type */
130+
public function columnType(int $column): int|false {}
131131

132-
/** @return array|false */
133-
public function fetchArray(int $mode = SQLITE3_BOTH) {}
132+
/** @tentative-return-type */
133+
public function fetchArray(int $mode = SQLITE3_BOTH): array|false {}
134134

135-
/** @return bool */
136-
public function reset() {}
135+
/** @tentative-return-type */
136+
public function reset(): bool {}
137137

138138
/** @return bool */
139-
public function finalize() {}
139+
public function finalize() {} // TODO make return type void
140140
}

0 commit comments

Comments
 (0)