- Issue created by @Ahmed Aziz ABBASSI
- @azizos opened merge request.
- @azizos opened merge request.
- Issue was unassigned.
- Status changed to Needs review
over 1 year ago 6:51am 22 June 2023
TypeError: Drupal\performance_profiler\PerformanceDatabaseActions::fillTable(): Return value must be of type array, int returned in Drupal\performance_profiler\PerformanceDatabaseActions->fillTable() (line 304 of modules/contrib/performance_profiler/src/PerformanceDatabaseActions.php).
Check the code implementation of that function:
public function fillTable(string $table, bool $is_ajax, string $insert_type = 'one_operation'): array {
try {
$table_name = self::TABLE_PREFIX . $table;
if ($this->database->query("SELECT id FROM {$table_name} LIMIT 1")->fetchField()) {
$this->messenger->addWarning("Skipped table {$table_name}, because it already has values.");
return 0;
}
$timer = 'mysql_fill_generation_benchmark';
$this->startTimer($timer);
$query_values = $this->generateValues($table, $insert_type == 'one_operation');
$columns = implode(', ', array_keys(self::tables()[$table]['columns']));
if ($insert_type == 'one_operation') {
$this->database->query("INSERT INTO `{$table_name}` ({$columns}) VALUES {$query_values}");
}
elseif (!empty($query_values) && is_array($query_values)) {
if ($insert_type == 'transaction') {
$transaction = $this->database->startTransaction();
}
try {
foreach ($query_values as $values) {
$this->database->query("INSERT INTO `{$table_name}` ({$columns}) VALUES {$values}");
}
}
catch (\Exception $exception) {
if ($insert_type == 'transaction') {
$transaction->rollBack();
}
}
if ($insert_type == 'transaction') {
unset($transaction);
}
}
return $this->stopAndLogTimer($timer, $is_ajax, "Generate and insert {$table_name}");
}
catch (\Exception $e) {
$this->messenger->addWarning("Failed executing query, {$e->getMessage()}");
}
return [
'message' => '',
'time' => 0,
];
}
We could see that the function could return a zero which is an int value.
Add int type hint.
public function fillTable(string $table, bool $is_ajax, string $insert_type = 'one_operation'): array | int
Needs review
1.0
Code