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

Commit

Permalink
Made identification of column names case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjaap committed Nov 27, 2021
1 parent 5100ca3 commit de8f560
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Elgentos/Masquerade/Console/IdentifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->setup();

$this->identifiers = [
'first_name',
'firstName',
'last_name',
'lastName',
'address',
'suffix',
Expand All @@ -95,6 +97,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
'company',
'remote_ip',
'ip_address',
'ipaddress',
'credit_card',
'creditCard',
'transaction'
];
Expand All @@ -105,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($tableNames as $tableName) {
$columns = $this->db->getSchemaBuilder()->getColumnListing($tableName);
foreach ($columns as $columnName) {
if ($formatter = $this->strposa($columnName, $this->identifiers)) {
if ($formatter = $this->striposa($columnName, $this->identifiers)) {
$exampleValues = array_filter(array_map(function ($exampleValue) use ($columnName) {
$string = $exampleValue->{$columnName};
if (strlen($string) > 30) {
Expand Down Expand Up @@ -144,7 +148,7 @@ private function setup()
$driver = $this->input->getOption('driver') ?? $databaseConfig['driver'] ?? 'mysql';
$database = $this->input->getOption('database') ?? $databaseConfig['database'];
$username = $this->input->getOption('username') ?? $databaseConfig['username'];
$password = $this->input->getOption('password') ?? isset($databaseConfig['password']) ? $databaseConfig['password'] : '';
$password = $this->input->getOption('password') ?? $databaseConfig['password'] ?? '';
$prefix = $this->input->getOption('prefix') ?? $databaseConfig['prefix'] ?? '';
$charset = $this->input->getOption('charset') ?? $databaseConfig['charset'] ?? 'utf8';

Expand Down Expand Up @@ -236,13 +240,13 @@ protected function getTableNames(): array
* @param int $offset
* @return bool
*/
protected function strposa($haystack, $needle, $offset = 0)
protected function striposa($haystack, $needle, int $offset = 0)
{
if (!is_array($needle)) {
$needle = array($needle);
}
foreach ($needle as $query) {
if (strpos($haystack, $query, $offset) !== false) {
if (stripos($haystack, $query, $offset) !== false) {
return $query;
}
}
Expand Down

0 comments on commit de8f560

Please sign in to comment.