Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Strip non utf8 code examples from identify command overview
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjaap committed Nov 27, 2021
1 parent c60bad1 commit 5100ca3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Elgentos/Masquerade/Console/IdentifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$columns = $this->db->getSchemaBuilder()->getColumnListing($tableName);
foreach ($columns as $columnName) {
if ($formatter = $this->strposa($columnName, $this->identifiers)) {
$exampleValues = array_map(function ($exampleValue) use ($columnName) {
$exampleValues = array_filter(array_map(function ($exampleValue) use ($columnName) {
$string = $exampleValue->{$columnName};
if (strlen($string) > 30) {
$string = substr($string, 0, 30) . '...';
}
return $string;
}, $this->db->table($tableName)->whereNotNull($columnName)->distinct()->inRandomOrder()->limit(3)->get([$columnName])->toArray());
return utf8_encode($string) === $string ? $string : false;
}, $this->db->table($tableName)->whereNotNull($columnName)->distinct()->inRandomOrder()->limit(3)->get([$columnName])->toArray()));
$candidates[] = [$tableName, $columnName, $formatter, implode(', ', $exampleValues)];
}
}
Expand Down

0 comments on commit 5100ca3

Please sign in to comment.