Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 authored and StyleCIBot committed Jul 9, 2024
1 parent 8b9929a commit 79bcea8
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions app/Database/migrations/2024_07_09_210356_update_db_charset.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
Expand Down Expand Up @@ -120,14 +117,14 @@ protected function extractInformationFromColumn($column)
}

return [
'field' => $column->Field,
'type' => $type,
'field' => $column->Field,
'type' => $type,
'type_brackets' => $typeBrackets,
'type_end' => $typeEnd,
'null' => strtolower($column->Null) == 'yes',
'default' => $column->Default,
'charset' => is_string($column->Collation) && ($pos = strpos($column->Collation, '_')) !== false ? substr($column->Collation, 0, $pos) : null,
'collation' => $column->Collation
'type_end' => $typeEnd,
'null' => strtolower($column->Null) == 'yes',
'default' => $column->Default,
'charset' => is_string($column->Collation) && ($pos = strpos($column->Collation, '_')) !== false ? substr($column->Collation, 0, $pos) : null,
'collation' => $column->Collation,
];
}

Expand Down Expand Up @@ -160,12 +157,12 @@ protected function isStringTypeWithLength($column)
* lengths of those columns that have them to be the newLength provided, when the shouldUpdateLength callback passed
* returns true.
*
* @param string $table
* @param string $charset
* @param string $collation
* @param int|null $newLength
* @param Closure|null $shouldUpdateLength
* @param string|null $connection
* @param string $table
* @param string $charset
* @param string $collation
* @param int|null $newLength
* @param Closure|null $shouldUpdateLength
* @param string|null $connection
*/
protected function updateColumnsInTable($table, $charset, $collation, $newLength = null, Closure $shouldUpdateLength = null, $connection = null)
{
Expand All @@ -175,28 +172,28 @@ protected function updateColumnsInTable($table, $charset, $collation, $newLength
$column = $this->extractInformationFromColumn($column);

if ($this->isStringType($column)) {
$sql = "CHANGE `%field%` `%field%` %type%%brackets% CHARACTER SET %charset% COLLATE %collation% %null% %default%";
$sql = 'CHANGE `%field%` `%field%` %type%%brackets% CHARACTER SET %charset% COLLATE %collation% %null% %default%';
$search = ['%field%', '%type%', '%brackets%', '%charset%', '%collation%', '%null%', '%default%'];
$replace = [
$column['field'],
$column['type'],
$column['type_brackets'] ? '(' . $column['type_brackets'] . ')' : '',
$column['type_brackets'] ? '('.$column['type_brackets'].')' : '',
$charset,
$collation,
$column['null'] ? 'NULL' : 'NOT NULL',
is_null($column['default']) ? ($column['null'] ? 'DEFAULT NULL' : '') : 'DEFAULT \'' . $column['default'] . '\''
is_null($column['default']) ? ($column['null'] ? 'DEFAULT NULL' : '') : 'DEFAULT \''.$column['default'].'\'',
];

if ($this->isStringTypeWithLength($column) && $shouldUpdateLength($column) && is_int($newLength) && $newLength > 0) {
$replace[2] = '(' . $newLength . ')';
$replace[2] = '('.$newLength.')';
}

$columnsToChange[] = trim(str_replace($search, $replace, $sql));
}
}

if (count($columnsToChange) > 0) {
$query = "ALTER TABLE `{$table}` " . implode(', ', $columnsToChange);
$query = "ALTER TABLE `{$table}` ".implode(', ', $columnsToChange);

$this->getDatabaseConnection($connection)->update($query);
}
Expand All @@ -212,7 +209,7 @@ protected function updateColumnsInTable($table, $charset, $collation, $newLength
*/
protected function getColumnsFromTable($table, $connection = null)
{
return $this->getDatabaseConnection($connection)->select('SHOW FULL COLUMNS FROM ' . $table);
return $this->getDatabaseConnection($connection)->select('SHOW FULL COLUMNS FROM '.$table);
}

/**
Expand Down

0 comments on commit 79bcea8

Please sign in to comment.