From 1c71296b3e7be9ac4089f3862e5d4002438e77c1 Mon Sep 17 00:00:00 2001 From: bogdankharchenko Date: Tue, 21 Dec 2021 14:21:30 +0000 Subject: [PATCH] Fix styling --- .php-cs-fixer.cache | 2 +- src/Models/HasSettings.php | 8 ++------ tests/Fixtures/SimpleSetting.php | 1 - tests/SettingsTest.php | 18 ++++++------------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache index 50733a0..0f8114a 100644 --- a/.php-cs-fixer.cache +++ b/.php-cs-fixer.cache @@ -1 +1 @@ -{"php":"8.1.0","version":"3.4.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}},"single_trait_insert_per_statement":true},"hashes":{"src\/Models\/HasSettings.php":3446277725,"src\/Models\/Setting.php":1606402483,"src\/ClassMorphMap.php":613274952,"src\/BaseSettings.php":204669101,"src\/Providers\/SettingsServiceProvider.php":3414138676,"src\/CachesSettings.php":258548273,"tests\/ClassMapTest.php":1928410964,"tests\/SettingsTest.php":2064399654,"tests\/Fixtures\/ComplexSetting.php":4179202307,"tests\/BaseTestCase.php":2037732410}} \ No newline at end of file +{"php":"8.1.0","version":"3.4.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}},"single_trait_insert_per_statement":true},"hashes":{"src\/Models\/HasSettings.php":3533225731,"src\/Models\/Setting.php":1606402483,"src\/ClassMorphMap.php":613274952,"src\/BaseSettings.php":204669101,"src\/Providers\/SettingsServiceProvider.php":3414138676,"src\/CachesSettings.php":258548273,"tests\/ClassMapTest.php":1928410964,"tests\/SettingsTest.php":842726344,"tests\/Fixtures\/ComplexSetting.php":4179202307,"tests\/BaseTestCase.php":335068492,"tests\/Fixtures\/SimpleSetting.php":448900176}} \ No newline at end of file diff --git a/src/Models/HasSettings.php b/src/Models/HasSettings.php index 3fa6ccf..b4cdc0d 100644 --- a/src/Models/HasSettings.php +++ b/src/Models/HasSettings.php @@ -11,7 +11,6 @@ trait HasSettings { - use ReflectsClosures; public function settings(): MorphMany @@ -19,7 +18,6 @@ public function settings(): MorphMany return $this->morphMany(Setting::class, 'settable'); } - public function setSettings(Closure $closure): self { $closureParameterTypes = $this->closureParameterTypes($closure); @@ -43,21 +41,19 @@ public function setSettings(Closure $closure): self return $this; } - public function getSettings($class) { return new $class($this); } - public function scopeWhereSettings(Builder $builder, $class, $name, $operator, $value = null) { $class = ClassMorphMap::getKeyFromClass($class); - $builder->whereHas('settings', function($builder) use ($class, $name, $operator, $value) { + $builder->whereHas('settings', function ($builder) use ($class, $name, $operator, $value) { $builder->where('class', $class); - $builder->where(function(Builder $builder) use ($name, $operator, $value) { + $builder->where(function (Builder $builder) use ($name, $operator, $value) { $builder->where("payload->{$name}", $operator ?? '=', $value ?? $operator); }); }); diff --git a/tests/Fixtures/SimpleSetting.php b/tests/Fixtures/SimpleSetting.php index 030fa6a..04a1022 100644 --- a/tests/Fixtures/SimpleSetting.php +++ b/tests/Fixtures/SimpleSetting.php @@ -6,6 +6,5 @@ class SimpleSetting extends BaseSettings { - public string $favoriteColor = 'red'; } diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 6e9bec0..acad825 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -10,11 +10,10 @@ class SettingsBaseTest extends BaseTestCase { - public function test_complex_data_types(): void { config([ - 'typed-settings.morph' => [ + 'typed-settings.morph' => [ 'complex' => ComplexSetting::class, ], 'typed-settings.cache.enabled' => false, @@ -52,12 +51,11 @@ public function test_complex_data_types(): void //$this->assertTrue($user->exists()); } - public function test_settings_can_be_set_with_closure(): void { config([ 'typed-settings.morph' => [ 'complex' => ComplexSetting::class ] ]); - $this->getUser()->setSettings(function(ComplexSetting $complex) { + $this->getUser()->setSettings(function (ComplexSetting $complex) { $complex->filling = 'cherry'; $complex->pi = 22.22; $complex->ingredients = [ 'cherry', 'eggs', 'butter' ]; @@ -73,14 +71,13 @@ public function test_settings_can_be_set_with_closure(): void $this->assertTrue($complex->isReady); } - public function test_settings_are_cachable_and_cache_is_cleared_when_settings_are_updated(): void { config([ 'typed-settings.morph' => [ 'complex' => ComplexSetting::class ] ]); config([ 'typed-settings.cache' => [ 'enabled' => true, - 'driver' => 'array', + 'driver' => 'array', 'seconds' => 30, ], ]); @@ -98,27 +95,26 @@ public function test_settings_are_cachable_and_cache_is_cleared_when_settings_ar $this->assertTrue(Cache::driver('array')->has($key)); - $user->setSettings(function(ComplexSetting $complex) { + $user->setSettings(function (ComplexSetting $complex) { $complex->filling = 'cherry'; }); $this->assertFalse(Cache::driver('array')->has($key)); } - public function test_you_may_pass_multiple_closures_when_setting(): void { $user = $this->getUser(); config([ - 'typed-settings.morph' => [ + 'typed-settings.morph' => [ 'complex' => ComplexSetting::class, 'simplex' => SimpleSetting::class, ], 'typed-settings.cache.enabled' => false, ]); - $user->setSettings(function(SimpleSetting $simple, ComplexSetting $complex) { + $user->setSettings(function (SimpleSetting $simple, ComplexSetting $complex) { $simple->favoriteColor = 'blue'; $complex->filling = 'cherry'; }); @@ -130,7 +126,6 @@ public function test_you_may_pass_multiple_closures_when_setting(): void $this->assertEquals('cherry', $complex->filling); } - protected function getUser(): User { $user = new User(); @@ -142,6 +137,5 @@ protected function getUser(): User class User extends Model { - use HasSettings; }