From c986e12b00e9569cca5e24e5072e7770ffc25efa Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 May 2021 07:37:37 -0500 Subject: [PATCH] formatting --- .../Database/Eloquent/Concerns/HasAttributes.php | 14 ++++++-------- src/Illuminate/Database/Eloquent/Model.php | 9 +++++---- .../Database/EloquentStrictLoadingTest.php | 2 +- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index e9570f9a5e1c..56b52971aa53 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -439,7 +439,7 @@ public function getRelationValue($key) } if ($this->preventsLazyLoading) { - $this->violatedLazyLoading($key); + $this->handleLazyLoadingViolation($key); } // If the "attribute" exists as a method on the model, we will just assume @@ -461,17 +461,15 @@ public function isRelation($key) } /** - * Handle a lazy loading violation, for example by throwing an exception. + * Handle a lazy loading violation. * * @param string $key - * @return void + * @return mixed */ - protected function violatedLazyLoading($key) + protected function handleLazyLoadingViolation($key) { - if (isset(static::$violatedLazyLoadingCallback)) { - call_user_func(static::$violatedLazyLoadingCallback, $this, $key); - - return; + if (isset(static::$lazyLoadingViolationCallback)) { + return call_user_func(static::$lazyLoadingViolationCallback, $this, $key); } throw new LazyLoadingViolationException($this, $key); diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 679515018eab..e8844d8d7dff 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -159,11 +159,11 @@ abstract class Model implements Arrayable, ArrayAccess, Jsonable, JsonSerializab protected static $modelsShouldPreventLazyLoading = false; /** - * The callback that is responsible for handing lazy loading violations. + * The callback that is responsible for handling lazy loading violations. * * @var callable|null */ - protected static $violatedLazyLoadingCallback; + protected static $lazyLoadingViolationCallback; /** * The name of the "created at" column. @@ -368,11 +368,12 @@ public static function preventLazyLoading($value = true) /** * Register a callback that is responsible for handling lazy loading violations. * - * @param callable $callback + * @param callable $callback + * @return void */ public static function handleLazyLoadingViolationUsing(callable $callback) { - static::$violatedLazyLoadingCallback = $callback; + static::$lazyLoadingViolationCallback = $callback; } /** diff --git a/tests/Integration/Database/EloquentStrictLoadingTest.php b/tests/Integration/Database/EloquentStrictLoadingTest.php index 81f04f557477..31a42e6d3439 100644 --- a/tests/Integration/Database/EloquentStrictLoadingTest.php +++ b/tests/Integration/Database/EloquentStrictLoadingTest.php @@ -154,7 +154,7 @@ public function modelTwos() return $this->hasMany(EloquentStrictLoadingTestModel2::class, 'model_1_id'); } - protected function violatedLazyLoading($key) + protected function handleLazyLoadingViolation($key) { throw new \RuntimeException("Violated {$key}"); }