Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstewartja authored and actions-user committed Sep 30, 2021
1 parent 134240b commit a1410b7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/LaravelAttributeObserverServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,24 @@ private function observeModels()
}

foreach (array_keys($this->observers) as $modelClass) {
if (!is_object($modelClass) && class_exists($modelClass)) {
if (! is_object($modelClass) && class_exists($modelClass)) {

// Carry on if no attribute observers are defined for this model
if (empty($this->observers[$modelClass])) {
continue;
}

foreach ($this->observers[$modelClass] as $observer) {
if (!is_object($observer) && class_exists($observer)) {
if (! is_object($observer) && class_exists($observer)) {
try {
$observerInstance = App::make($observer);
$observerEventsAttribs = $this->parseObserverMethods($observerInstance);
$observedEvents = array_keys($observerEventsAttribs);

foreach ($observedEvents as $observedEvent) {
$modelClass::{$observedEvent}(function (Model $model) use ($observedEvent, $observerEventsAttribs, $observerInstance) {

if ($model->wasChanged()) {
foreach ($observerEventsAttribs[$observedEvent] as $attribute) {

if ($this->modelHasAttribute($model, $attribute) && $model->wasChanged($attribute)) {
$method = 'on' . Str::studly($attribute) . Str::ucfirst($observedEvent);
$observerInstance->{$method}($model, $model->getAttributeValue($attribute), $model->getOriginal($attribute));
Expand All @@ -88,6 +86,7 @@ private function observeModels()
}
} catch (BindingResolutionException $bindingResolutionException) {
Log::error($bindingResolutionException);

continue;
}
}
Expand All @@ -104,7 +103,7 @@ private function observeModels()
*/
private function parseObserverMethods(object|string $observer_object_or_class): array
{
$events_attribs_mapping = array();
$events_attribs_mapping = [];

// Methods that react to attribute changes start with 'on'. Let's grab those...
$observerMethods = array_map(
Expand Down Expand Up @@ -141,7 +140,7 @@ function ($method) {
*/
private function modelHasAttribute(Model $model, string $attribute): bool
{
return !method_exists($model, $attribute) &&
return ! method_exists($model, $attribute) &&
(array_key_exists($attribute, $model->getAttributes()) ||
array_key_exists($attribute, $model->getCasts()) ||
$model->hasGetMutator($attribute) ||
Expand Down

0 comments on commit a1410b7

Please sign in to comment.