Skip to content

Commit

Permalink
further refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 11, 2016
1 parent a47aeb2 commit 99dc5b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/ActivityLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion tests/CustomActivityModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 99dc5b4

Please sign in to comment.