Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter authored and github-actions[bot] committed Jul 19, 2024
1 parent 1ac5f01 commit e982e29
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function up(): void

$table->enum('types', ['one', 'two'])->default('one'); // default => ignored

if ((float) App::version() >= Constants::VERSION_AFTER_UUID_SUPPORT && DB::connection()->getDriverName() !== 'mariadb') {
if ((float) App::version() >= Constants::VERSION_AFTER_UUID_SUPPORT && DB::connection()->getDriverName() !== 'mariadb') {
$table->uuid('uuid'); // required
} else {
$table->string('uuid');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use WatheqAlshowaiter\ModelRequiredFields\Constants;
use Illuminate\Support\Facades\DB;

class CreateSonsTable extends Migration
{
Expand Down
30 changes: 14 additions & 16 deletions src/RequiredFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static function getRequiredFields(
return collect(Schema::getColumns((new self())->getTable()))
->reject(function ($column) use ($primaryIndex, $withNullables, $withDefaults) {
return
$column['nullable'] && !$withNullables ||
$column['default'] != null && !$withDefaults ||
$column['nullable'] && ! $withNullables ||
$column['default'] != null && ! $withDefaults ||
(in_array($column['name'], $primaryIndex));
})
->pluck('name')
Expand Down Expand Up @@ -109,12 +109,11 @@ private static function getRequiredFieldsForSqlite(
return (array) $column;
}, $queryResult);


return collect($queryResult)
->reject(function ($column) use ($withNullables, $withDefaults, $withPrimaryKey) {
return $column['pk'] && !$withPrimaryKey
|| $column['dflt_value'] != null && !$withDefaults
|| !$column['notnull'] && !$withNullables;
return $column['pk'] && ! $withPrimaryKey
|| $column['dflt_value'] != null && ! $withDefaults
|| ! $column['notnull'] && ! $withNullables;
})
->pluck('name')
->toArray();
Expand Down Expand Up @@ -155,9 +154,9 @@ private static function getRequiredFieldsForMysqlAndMariaDb(

return collect($queryResult)
->reject(function ($column) use ($withNullables, $withDefaults, $withPrimaryKey) {
return $column['primary'] && !$withPrimaryKey
|| $column['default'] != null && !$withDefaults
|| $column['nullable'] && !$withNullables;
return $column['primary'] && ! $withPrimaryKey
|| $column['default'] != null && ! $withDefaults
|| $column['nullable'] && ! $withNullables;
})
->pluck('name')
->toArray();
Expand Down Expand Up @@ -231,9 +230,9 @@ private static function getRequiredFieldsForPostgres(
}, $queryResult);

$result = collect($queryResult)
->reject(function ($column) use ($primaryIndex, $withPrimaryKey, $withDefaults, $withNullables) {
return ($column['default'] && !$withDefaults) ||
($column['nullable'] == 'YES' && !$withNullables) ||
->reject(function ($column) use ($primaryIndex, $withDefaults, $withNullables) {
return ($column['default'] && ! $withDefaults) ||
($column['nullable'] == 'YES' && ! $withNullables) ||
(in_array($column['name'], $primaryIndex));
})
->pluck('name')
Expand All @@ -247,7 +246,6 @@ private static function getRequiredFieldsForPostgres(
return $result;
}


/**
* Not tested yet in machine with SQL SERVER
*
Expand Down Expand Up @@ -286,9 +284,9 @@ private static function getRequiredFieldsForSqlServer(

return collect($queryResult)
->reject(function ($column) use ($withDefaults, $withNullables, $withPrimaryKey) {
return $column['primary'] && !$withPrimaryKey
|| $column['default'] != null && !$withDefaults
|| $column['nullable'] && !$withNullables;
return $column['primary'] && ! $withPrimaryKey
|| $column['default'] != null && ! $withDefaults
|| $column['nullable'] && ! $withNullables;
})
->pluck('name')
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getEnvironmentSetUp($app)
}

// if not supported above then stop the test
if (!in_array($dbConnection, ['mysql', 'mariadb', 'pgsql', 'sqlite', 'sqlsrv'])) {
if (! in_array($dbConnection, ['mysql', 'mariadb', 'pgsql', 'sqlite', 'sqlsrv'])) {
echo "database {$dbConnection} is not supported";
exit;
}
Expand Down

0 comments on commit e982e29

Please sign in to comment.