From bfcabc71bca9f1f074d4a1231be3a3a429d465b1 Mon Sep 17 00:00:00 2001 From: WatheqAlshowaiter Date: Thu, 18 Jul 2024 20:16:00 +0000 Subject: [PATCH] Fix styling --- src/RequiredFields.php | 32 +++++++++++++++++--------------- tests/RequiredFieldsTest.php | 3 ++- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/RequiredFields.php b/src/RequiredFields.php index 7e6baaf..3ec292a 100644 --- a/src/RequiredFields.php +++ b/src/RequiredFields.php @@ -39,9 +39,9 @@ public static function getRequiredFields( return collect(Schema::getColumns((new self())->getTable())) ->reject(function ($column) use ($primaryIndex, $withNullables, $withDefaults, $withPrimaryKey) { return - $column['nullable'] && !$withNullables - || $column['default'] != null && !$withDefaults - || in_array($column['name'], $primaryIndex) && !$withPrimaryKey; + $column['nullable'] && ! $withNullables + || $column['default'] != null && ! $withDefaults + || in_array($column['name'], $primaryIndex) && ! $withPrimaryKey; }) ->pluck('name') ->toArray(); @@ -109,9 +109,9 @@ private static function getRequiredFieldsForSqlite( 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(); @@ -152,9 +152,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(); @@ -237,9 +237,9 @@ private static function getRequiredFieldsForPostgres( return collect($queryResult) ->reject(function ($column) use ($primaryIndex, $withPrimaryKey, $withDefaults, $withNullables) { return - $column['default'] && !$withDefaults - || $column['nullable'] == 'YES' && !$withNullables - || in_array($column['name'], $primaryIndex) && !$withPrimaryKey; + $column['default'] && ! $withDefaults + || $column['nullable'] == 'YES' && ! $withNullables + || in_array($column['name'], $primaryIndex) && ! $withPrimaryKey; }) ->pluck('name') ->toArray(); @@ -283,9 +283,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(); @@ -320,10 +320,12 @@ public static function getRequiredFieldsWithDefaultsAndPrimaryKey() { return self::getRequiredFields($withNullables = false, $withDefaults = true, $withPrimaryKey = true); } + public static function getRequiredFieldsWithNullablesAndDefaults() { return self::getRequiredFields($withNullables = true, $withDefaults = true, $withPrimaryKey = false); } + public static function getRequiredFieldsWithNullablesAndPrimaryKey() { return self::getRequiredFields($withNullables = true, $withDefaults = false, $withPrimaryKey = true); diff --git a/tests/RequiredFieldsTest.php b/tests/RequiredFieldsTest.php index 25768f7..7584e09 100644 --- a/tests/RequiredFieldsTest.php +++ b/tests/RequiredFieldsTest.php @@ -119,6 +119,7 @@ public function test_get_required_with_nullables_and_defaults() )); $this->assertEquals($expected, Father::getRequiredFieldsWithNullablesAndDefaults()); } + public function test_get_required_with_nullables_and_primary_key() { $expected = [ @@ -176,7 +177,7 @@ public function test_get_required_with_defaults_and_nullables_and_primary_key() 'username', 'created_at', 'updated_at', - 'deleted_at' + 'deleted_at', ]; $this->assertEquals($expected, Father::getRequiredFields(