Skip to content

Commit 3986a98

Browse files
committed
- Fixed some issues reported by phpstan
1 parent d3d00db commit 3986a98

File tree

5 files changed

+7
-89
lines changed

5 files changed

+7
-89
lines changed

src/Builder/Insert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ private function addTo(array $fields, string $field, $value): array {
243243
* @param array<string, mixed> $data
244244
* @param array<int, string>|null $mask
245245
* @param array<int, string>|null $excludeFields
246-
* @param null|callable(string, mixed): void $fn
246+
* @param callable(string, mixed): void $fn
247247
*/
248-
private function addAllTo(array $data, ?array $mask = null, ?array $excludeFields = null, $fn = null): void {
248+
private function addAllTo(array $data, ?array $mask, ?array $excludeFields, $fn): void {
249249
if($mask !== null) {
250250
$data = array_intersect_key($data, array_combine($mask, $mask));
251251
}

src/Builder/RunnableSelect.php

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -118,86 +118,7 @@ public function fetchValue($default = null, ?callable $fn = null);
118118
public function getFoundRows(): int;
119119

120120
/**
121-
* @return Traversable|array[]
122-
*/
123-
public function getIterator() {
124-
/** @var Traversable|array[] $result */
125-
$result = $this->fetchRowsLazy();
126-
return $result;
127-
}
128-
129-
/**
130-
* @param Closure|null $callback
131-
* @param int $mode
132-
* @param mixed $arg0
133-
* @return mixed
134-
*/
135-
private function fetchAll(Closure $callback = null, int $mode = 0, $arg0 = null) {
136-
return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) {
137-
$statement->setFetchMode($mode, $arg0);
138-
$data = $statement->fetchAll();
139-
if($this->preserveTypes) {
140-
$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
141-
$data = array_map(static function ($row) use ($columnDefinitions) {
142-
return FieldValueConverter::convertValues($row, $columnDefinitions);
143-
}, $data);
144-
}
145-
if($callback !== null) {
146-
return call_user_func(static function ($resultData = []) use ($data, $callback) {
147-
foreach($data as $row) {
148-
$result = $callback($row);
149-
if($result !== null && !($result instanceof DBIgnoreRow)) {
150-
$resultData[] = $result;
151-
} else {
152-
$resultData[] = $row;
153-
}
154-
}
155-
return $resultData;
156-
});
157-
}
158-
return $data;
159-
});
160-
}
161-
162-
/**
163-
* @param Closure|null $callback
164-
* @param int $mode
165-
* @param mixed $arg0
166-
* @return Traversable|mixed[]
167-
*/
168-
private function fetchLazy(Closure $callback = null, int $mode = PDO::FETCH_ASSOC, $arg0 = null) {
169-
$statement = $this->createStatement();
170-
$statement->setFetchMode($mode, $arg0);
171-
$generator = new LazyRowGenerator($this->preserveTypes);
172-
return $generator->generate($statement, $callback);
173-
}
174-
175-
/**
176-
* @param Closure|null $callback
177-
* @param int $mode
178-
* @param mixed $arg0
179-
* @param Closure|null $resultValidator
180-
* @return mixed
181-
*/
182-
private function fetch(Closure $callback = null, int $mode = PDO::FETCH_ASSOC, $arg0 = null, Closure $resultValidator = null) {
183-
return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
184-
$statement->setFetchMode($mode, $arg0);
185-
$row = $statement->fetch();
186-
$result = $resultValidator($row);
187-
if(!$result['valid']) {
188-
return $result['default'];
189-
}
190-
if($this->preserveTypes) {
191-
$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
192-
$row = FieldValueConverter::convertValues($row, $columnDefinitions);
193-
}
194-
if($callback !== null) {
195-
$result = $callback($row);
196-
if($result !== null) {
197-
$row = $result;
198-
}
199-
}
200-
return $row;
201-
});
202-
}
121+
* @return Generator<int, array<string, mixed>>
122+
*/
123+
public function getIterator();
203124
}

src/Builder/Traits/AbstractDB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ trait AbstractDB {
77
/**
88
* @return Database
99
*/
10-
abstract protected function db(): Database;
10+
abstract protected function db();
1111
}

src/Builder/Traits/TableNameBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ protected function buildTableName(?string $alias, $name): string {
5050
/**
5151
* @return Database
5252
*/
53-
abstract protected function db(): MySQL;
53+
abstract protected function db();
5454
}

tests/Builder/SelectTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ public function testOptionalExpressions(): void {
441441

442442
self::assertEquals("SELECT\n\tt.field\nFROM\n\ttest t\nWHERE\n\t(t.field IN (1, 2, 3))\n", $query);
443443

444-
}
445-
446-
public function testOptionalExpressions2() {
447444
$filter = ['filter' => ['name' => 'aaa', 'ids' => [1, 2, 3]]];
448445
$opt = new OptionalDBFilterMap($filter);
449446

0 commit comments

Comments
 (0)