Skip to content

Commit

Permalink
Modify using helper methods to facades (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaelftah authored and freekmurze committed Feb 1, 2019
1 parent 2ed89a8 commit 6188a98
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog;

use Illuminate\Support\Arr;
use Illuminate\Auth\AuthManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Traits\Macroable;
Expand Down Expand Up @@ -175,7 +176,7 @@ protected function replacePlaceholders(string $description, ActivityContract $ac

$attributeValue = $attributeValue->toArray();

return array_get($attributeValue, $propertyName, $match);
return Arr::get($attributeValue, $propertyName, $match);
}, $description);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog\Models;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function causer(): MorphTo

public function getExtraProperty(string $propertyName)
{
return array_get($this->properties->toArray(), $propertyName);
return Arr::get($this->properties->toArray(), $propertyName);
}

public function changes(): Collection
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/DetectsChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog\Traits;

use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Exceptions\CouldNotLogChanges;

Expand Down Expand Up @@ -114,7 +115,7 @@ public static function logChanges(Model $model): array
{
$changes = [];
foreach ($model->attributesToBeLogged() as $attribute) {
if (str_contains($attribute, '.')) {
if (Str::contains($attribute, '.')) {
$changes += self::getRelatedModelAttributeValue($model, $attribute);
} else {
$changes += collect($model)->only($attribute)->toArray();
Expand Down
5 changes: 3 additions & 2 deletions src/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog\Traits;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Spatie\Activitylog\ActivityLogger;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -119,13 +120,13 @@ protected function shouldLogEvent(string $eventName): bool
return true;
}

if (array_has($this->getDirty(), 'deleted_at')) {
if (Arr::has($this->getDirty(), 'deleted_at')) {
if ($this->getDirty()['deleted_at'] === null) {
return false;
}
}

//do not log update event if only ignored attributes are changed
return (bool) count(array_except($this->getDirty(), $this->attributesToBeIgnored()));
return (bool) count(Arr::except($this->getDirty(), $this->attributesToBeIgnored()));
}
}
3 changes: 2 additions & 1 deletion tests/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog\Test\Models;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function causer(): MorphTo

public function getExtraProperty(string $propertyName)
{
return array_get($this->properties->toArray(), $propertyName);
return Arr::get($this->properties->toArray(), $propertyName);
}

public function changes(): Collection
Expand Down
3 changes: 2 additions & 1 deletion tests/Models/AnotherInvalidActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Activitylog\Test\Models;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function causer(): MorphTo
*/
public function getExtraProperty(string $propertyName)
{
return array_get($this->properties->toArray(), $propertyName);
return Arr::get($this->properties->toArray(), $propertyName);
}

public function changes(): Collection
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Activitylog\Test;

use CreateActivityLogTable;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Schema;
use Spatie\Activitylog\Models\Activity;
use Spatie\Activitylog\Test\Models\User;
Expand All @@ -23,7 +24,7 @@ public function setUp()
protected function checkRequirements()
{
collect($this->getAnnotations())->filter(function ($location) {
return in_array('!Travis', array_get($location, 'requires', []));
return in_array('!Travis', Arr::get($location, 'requires', []));
})->each(function ($location) {
getenv('TRAVIS') && $this->markTestSkipped('Travis will not run this test.');
});
Expand Down

0 comments on commit 6188a98

Please sign in to comment.