Skip to content

Commit cb5362b

Browse files
committed
🚨 Fix tentative return type issues and remove php8 checks
1 parent af4c575 commit cb5362b

14 files changed

+58
-98
lines changed

composer-require-checker.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@
22
"symbol-whitelist" : [
33
"null", "true", "false",
44
"static", "self", "parent",
5-
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
5+
"array",
6+
"string",
7+
"int",
8+
"float",
9+
"bool",
10+
"iterable",
11+
"callable",
12+
"void",
13+
"object",
14+
"mixed",
615
"WeakRef", "WeakReference",
716
"TheCodingMachine\\TDBM\\Fixtures\\Interfaces\\TestUserDaoInterface",
817
"TheCodingMachine\\TDBM\\Fixtures\\Traits\\TestUserDaoTrait",

phpstan.neon

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ parameters:
55
level: 7
66
inferPrivatePropertyTypeFromConstructor: true
77
excludePaths:
8-
- src/SafeFunctions.php # Temporary exclude, delete this file in PHP ^8.0
98
- src/Test/* # Files generated during TDBM test
10-
- src/AlterableResultIterator.php # TODO: Add tentative return type
11-
- src/EmptyInnerResultIterator.php # TODO: Add tentative return type
12-
- src/PageIterator.php # TODO: Add tentative return type
13-
- src/ResultIterator.php # TODO: Add tentative return type
14-
- src/InnerResultIterator.php # TODO: Add tentative return type
15-
- src/InnerResultArray.php # TODO: Add tentative return type
16-
- src/MapIterator.php # TODO: Add tentative return type
17-
- src/TDBMObject.php # TODO: Add tentative return type
189
ignoreErrors:
1910
-
2011
identifier: missingType.iterableValue
2112
-
2213
identifier: missingType.generics
23-
#- "#Method JsonSerializable::jsonSerialize\\(\\) invoked with 1 parameter, 0 required.#"
14+
- "#Method JsonSerializable::jsonSerialize\\(\\) invoked with 1 parameter, 0 required.#"
2415
- "#Call to an undefined method object::#"
2516
- "#expects TheCodingMachine\\\\TDBM\\\\AbstractTDBMObject, object given.#"
2617
- '#Method TheCodingMachine\\TDBM\\NativeWeakrefObjectStorage::get\(\) should return TheCodingMachine\\TDBM\\DbRow\|null but returns object\|null.#'

src/AlterableResultIterator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function toArray(): array
140140
*
141141
* @since 5.0.0
142142
*/
143-
public function offsetExists($offset)
143+
public function offsetExists($offset): bool
144144
{
145145
return isset($this->toArray()[$offset]);
146146
}
@@ -158,7 +158,7 @@ public function offsetExists($offset)
158158
*
159159
* @since 5.0.0
160160
*/
161-
public function offsetGet($offset)
161+
public function offsetGet($offset): mixed
162162
{
163163
return $this->toArray()[$offset];
164164
}
@@ -209,7 +209,7 @@ public function take(int $offset, int $limit): PageInterface
209209
*
210210
* @return int
211211
*/
212-
public function count()
212+
public function count(): int
213213
{
214214
if ($this->resultIterator instanceof \Countable && $this->alterations->count() === 0) {
215215
return $this->resultIterator->count();
@@ -222,7 +222,7 @@ public function count()
222222
*
223223
* @return \Traversable
224224
*/
225-
public function getIterator()
225+
public function getIterator(): \Traversable
226226
{
227227
if ($this->alterations->count() === 0) {
228228
if ($this->resultIterator !== null) {
@@ -245,7 +245,7 @@ public function getIterator()
245245
*
246246
* @since 5.4.0
247247
*/
248-
public function jsonSerialize()
248+
public function jsonSerialize(): mixed
249249
{
250250
return $this->toArray();
251251
}

src/DbRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function getRef(string $foreignKeyName, string $className, string $result
294294
$foreignColumns = $fk->getUnquotedForeignColumns();
295295
$foreignTableName = $fk->getForeignTableName();
296296

297-
$filter = SafeFunctions::arrayCombine($foreignColumns, $values);
297+
$filter = array_combine($foreignColumns, $values);
298298

299299
// If the foreign key points to the primary key, let's use findObjectByPk
300300
if ($this->tdbmService->getPrimaryKeyColumns($foreignTableName) === $foreignColumns) {

src/EmptyInnerResultIterator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class EmptyInnerResultIterator implements Iterator, InnerResultIteratorInterface
1515
* @return mixed Can return any type.
1616
* @since 5.0.0
1717
*/
18-
public function current()
18+
public function current(): mixed
1919
{
2020
return null;
2121
}
@@ -26,7 +26,7 @@ public function current()
2626
* @return void Any returned value is ignored.
2727
* @since 5.0.0
2828
*/
29-
public function next()
29+
public function next(): void
3030
{
3131
}
3232

@@ -36,7 +36,7 @@ public function next()
3636
* @return mixed scalar on success, or null on failure.
3737
* @since 5.0.0
3838
*/
39-
public function key()
39+
public function key(): mixed
4040
{
4141
return null;
4242
}
@@ -48,7 +48,7 @@ public function key()
4848
* Returns true on success or false on failure.
4949
* @since 5.0.0
5050
*/
51-
public function valid()
51+
public function valid(): bool
5252
{
5353
return false;
5454
}
@@ -59,7 +59,7 @@ public function valid()
5959
* @return void Any returned value is ignored.
6060
* @since 5.0.0
6161
*/
62-
public function rewind()
62+
public function rewind(): void
6363
{
6464
}
6565

@@ -75,7 +75,7 @@ public function rewind()
7575
* The return value will be casted to boolean if non-boolean was returned.
7676
* @since 5.0.0
7777
*/
78-
public function offsetExists($offset)
78+
public function offsetExists($offset): bool
7979
{
8080
return false;
8181
}
@@ -89,7 +89,7 @@ public function offsetExists($offset)
8989
* @return mixed Can return all value types.
9090
* @since 5.0.0
9191
*/
92-
public function offsetGet($offset)
92+
public function offsetGet($offset): mixed
9393
{
9494
throw new TDBMInvalidOffsetException('Offset "'.$offset.'" does not exist in result set.');
9595
}
@@ -134,7 +134,7 @@ public function offsetUnset($offset): void
134134
* The return value is cast to an integer.
135135
* @since 5.1.0
136136
*/
137-
public function count()
137+
public function count(): int
138138
{
139139
return 0;
140140
}

src/InnerResultArray.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class InnerResultArray extends InnerResultIterator
5252
*
5353
* @since 5.0.0
5454
*/
55-
public function offsetExists($offset)
55+
public function offsetExists($offset): bool
5656
{
5757
try {
5858
$this->toIndex($offset);
@@ -76,7 +76,7 @@ public function offsetExists($offset)
7676
*
7777
* @since 5.0.0
7878
*/
79-
public function offsetGet($offset)
79+
public function offsetGet($offset): mixed
8080
{
8181
$this->toIndex($offset);
8282

@@ -121,7 +121,7 @@ public function next(): void
121121
* Overloads the rewind implementation.
122122
* Do not reexecute the query.
123123
*/
124-
public function rewind()
124+
public function rewind(): void
125125
{
126126
if (!$this->fetchStarted) {
127127
$this->executeQuery();

src/InnerResultIterator.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
*/
3535
class InnerResultIterator implements \Iterator, InnerResultIteratorInterface
3636
{
37-
/** @var Result */
38-
protected $result;
37+
protected ?Result $result = null;
3938

4039
/** @var bool */
4140
protected $fetchStarted = false;
@@ -126,7 +125,7 @@ protected function executeQuery(): void
126125
*
127126
* @return int
128127
*/
129-
public function count()
128+
public function count(): int
130129
{
131130
if ($this->count !== null) {
132131
return $this->count;
@@ -160,7 +159,7 @@ private function getRowCountViaSqlQuery(): int
160159
*
161160
* @return AbstractTDBMObject
162161
*/
163-
public function current()
162+
public function current(): mixed
164163
{
165164
return $this->current;
166165
}
@@ -170,7 +169,7 @@ public function current()
170169
*
171170
* @return int
172171
*/
173-
public function key()
172+
public function key(): mixed
174173
{
175174
return $this->key;
176175
}
@@ -269,7 +268,7 @@ public function next(): void
269268
/**
270269
* Moves the cursor to the beginning of the result set.
271270
*/
272-
public function rewind()
271+
public function rewind(): void
273272
{
274273
$this->executeQuery();
275274
$this->key = -1;
@@ -280,7 +279,7 @@ public function rewind()
280279
*
281280
* @return bool
282281
*/
283-
public function valid()
282+
public function valid(): bool
284283
{
285284
return $this->current !== null;
286285
}
@@ -301,7 +300,7 @@ public function valid()
301300
*
302301
* @since 5.0.0
303302
*/
304-
public function offsetExists($offset)
303+
public function offsetExists($offset): bool
305304
{
306305
throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
307306
}
@@ -319,7 +318,7 @@ public function offsetExists($offset)
319318
*
320319
* @since 5.0.0
321320
*/
322-
public function offsetGet($offset)
321+
public function offsetGet($offset): mixed
323322
{
324323
throw new TDBMInvalidOperationException('You cannot access this result set via index because it was fetched in CURSOR mode. Use ARRAY_MODE instead.');
325324
}

src/MapIterator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,32 @@ public function __construct($iterator, callable $callable)
6464
*
6565
* @return mixed
6666
*/
67-
public function current()
67+
public function current(): mixed
6868
{
6969
$callable = $this->callable;
7070

7171
return $callable($this->iterator->current());
7272
}
7373

74-
public function next()
74+
public function next(): void
7575
{
7676
$this->iterator->next();
7777
}
7878

7979
/**
8080
* @return mixed
8181
*/
82-
public function key()
82+
public function key(): mixed
8383
{
8484
return $this->iterator->key();
8585
}
8686

87-
public function valid()
87+
public function valid(): bool
8888
{
8989
return $this->iterator->valid();
9090
}
9191

92-
public function rewind()
92+
public function rewind(): void
9393
{
9494
$this->iterator->rewind();
9595
}
@@ -104,7 +104,7 @@ public function toArray(): array
104104
return iterator_to_array($this);
105105
}
106106

107-
public function jsonSerialize()
107+
public function jsonSerialize(): mixed
108108
{
109109
return $this->toArray();
110110
}

src/PageIterator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function createEmpyIterator(ResultIterator $parentResult): self
117117
*
118118
* @return InnerResultIteratorInterface
119119
*/
120-
public function getIterator()
120+
public function getIterator(): \Traversable
121121
{
122122
if ($this->innerResultIterator === null) {
123123
if ($this->parentResult->count() === 0) {
@@ -204,7 +204,7 @@ public function map(callable $callable): MapIterator
204204
*
205205
* @since 5.0.0
206206
*/
207-
public function offsetExists($offset)
207+
public function offsetExists($offset): bool
208208
{
209209
return $this->getIterator()->offsetExists($offset);
210210
}
@@ -222,7 +222,7 @@ public function offsetExists($offset)
222222
*
223223
* @since 5.0.0
224224
*/
225-
public function offsetGet($offset)
225+
public function offsetGet($offset): mixed
226226
{
227227
return $this->getIterator()->offsetGet($offset);
228228
}
@@ -272,7 +272,7 @@ public function offsetUnset($offset): void
272272
*
273273
* @since 5.4.0
274274
*/
275-
public function jsonSerialize()
275+
public function jsonSerialize(): mixed
276276
{
277277
return array_map(function (AbstractTDBMObject $item) {
278278
return $item->jsonSerialize();

src/ResultIterator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function map(callable $callable): MapIterator
160160
*
161161
* @return InnerResultIteratorInterface
162162
*/
163-
public function getIterator()
163+
public function getIterator(): \Traversable
164164
{
165165
if ($this->innerResultIterator === null) {
166166
if ($this->totalCount === 0) {
@@ -199,7 +199,7 @@ public function take(int $offset, int $limit): PageIterator
199199
*
200200
* @since 5.0.0
201201
*/
202-
public function offsetExists($offset)
202+
public function offsetExists($offset): bool
203203
{
204204
return $this->getIterator()->offsetExists($offset);
205205
}
@@ -217,7 +217,7 @@ public function offsetExists($offset)
217217
*
218218
* @since 5.0.0
219219
*/
220-
public function offsetGet($offset)
220+
public function offsetGet($offset): mixed
221221
{
222222
return $this->getIterator()->offsetGet($offset);
223223
}
@@ -271,7 +271,7 @@ public function offsetUnset($offset): void
271271
*
272272
* @since 5.4.0
273273
*/
274-
public function jsonSerialize($stopRecursion = false)
274+
public function jsonSerialize($stopRecursion = false): mixed
275275
{
276276
return array_map(function (AbstractTDBMObject $item) use ($stopRecursion) {
277277
return $item->jsonSerialize($stopRecursion);

0 commit comments

Comments
 (0)