From 99dc5b42d835aa5b6c8a0597054c9d03281313e5 Mon Sep 17 00:00:00 2001 From: freek Date: Thu, 11 Aug 2016 13:46:26 +0200 Subject: [PATCH] further refactorings --- src/ActivityLogger.php | 16 ++++------------ tests/CustomActivityModelTest.php | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/ActivityLogger.php b/src/ActivityLogger.php index 3435a100..ae79d48c 100644 --- a/src/ActivityLogger.php +++ b/src/ActivityLogger.php @@ -25,17 +25,12 @@ class ActivityLogger /** @var \Illuminate\Support\Collection */ protected $properties; - /** @var \Spatie\Activitylog\Models\Activity */ - protected $activityModel; - public function __construct(AuthManager $auth, Repository $config) { $this->auth = $auth; $this->properties = collect(); - $this->activityModel = $this->determineActivityModel(); - $authDriver = $config['laravel-activitylog']['default_auth_driver'] ?? $auth->getDefaultDriver(); $this->causedBy = $auth->guard($authDriver)->user(); @@ -113,7 +108,9 @@ public function inLog(string $logName) public function log(string $description) { - $activity = new $this->activityModel(); + $activityModelClassName = $this->determineActivityModel(); + + $activity = new $activityModelClassName(); if ($this->performedOn) { $activity->subject()->associate($this->performedOn); @@ -176,17 +173,12 @@ protected function replacePlaceholders(string $description, Activity $activity): }, $description); } - public function getActivityModel() : string - { - return $this->activityModel; - } - /** * @return \Illuminate\Database\Eloquent\Model * * @throws \Spatie\Activitylog\Exceptions\InvalidConfiguration */ - protected function determineActivityModel() + public function determineActivityModel() { $activityModel = config('laravel-activitylog.activity_model') ?? Activity::class; diff --git a/tests/CustomActivityModelTest.php b/tests/CustomActivityModelTest.php index acf835c1..68ba538b 100644 --- a/tests/CustomActivityModelTest.php +++ b/tests/CustomActivityModelTest.php @@ -30,7 +30,8 @@ public function it_can_log_activity_using_a_custom_model() $activity = activity()->log($this->activityDescription); $this->assertEquals($this->activityDescription, $this->getLastActivity()->description); - $this->assertEquals(CustomActivityModel::class, $activity->getActivityModel()); + + $this->assertEquals(CustomActivityModel::class, $activity->determineActivityModel()); } /** @test */