Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Contract Achievementable —> HasAchievements;
Trait Achievementable –> InteractsWitchAchievements
  • Loading branch information
iooe committed Apr 18, 2021
1 parent 3cf3828 commit 54bf7a1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ php artisan vendor:publish --provider="tizis\achievements\Providers\ServiceProvi


```php
use tizis\achievements\Contracts\Achievementable as AchievementableContract;
use tizis\achievements\Traits\Achievementable;
use tizis\achievements\Contracts\HasAchievements;
use tizis\achievements\Traits\InteractsWithAchievements;

class User extends Authenticatable implements AchievementableContract {
use Achievementable;
class User extends Authenticatable implements HasAchievements {
use InteractsWithAchievements;
}
```

Expand Down
12 changes: 6 additions & 6 deletions src/AchievementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace tizis\achievements;

use tizis\achievements\Contracts\Achievementable;
use tizis\achievements\Contracts\HasAchievements;

class AchievementHelper
{
public static function count(Achievementable $user)
public static function count(HasAchievements $user)
{
return $user->achievements()
->wherePivot('unlocked_at', '!=', null)
->count();
}

public static function lastUnlockedAchievements(Achievementable $user, int $take = 10)
public static function lastUnlockedAchievements(HasAchievements $user, int $take = 10)
{
return $user->achievements()
->wherePivot('unlocked_at', '!=', null)
Expand All @@ -22,15 +22,15 @@ public static function lastUnlockedAchievements(Achievementable $user, int $take
->get();
}

public static function lastUnlockedAchievement(Achievementable $user)
public static function lastUnlockedAchievement(HasAchievements $user)
{
return $user->achievements()
->wherePivot('unlocked_at', '!=', null)
->orderBy('achievements_progress.unlocked_at', 'desc')
->first();
}

public static function getUnlockedUniqueAchievementsOfUser(Achievementable $user)
public static function getUnlockedUniqueAchievementsOfUser(HasAchievements $user)
{
$collection = collect();

Expand Down Expand Up @@ -63,7 +63,7 @@ public static function getUnlockedUniqueAchievementsOfUser(Achievementable $user
return $collection;
}

public static function unlockedAchievementsOnlyGroups(Achievementable $user)
public static function unlockedAchievementsOnlyGroups(HasAchievements $user)
{
$collection = collect();

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Achievementable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace tizis\achievements\Contracts;

interface Achievementable
interface HasAchievements
{
public function achievements(): \Illuminate\Database\Eloquent\Relations\BelongsToMany;

Expand Down
6 changes: 3 additions & 3 deletions src/Services/AchievementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace tizis\achievements\Services;

use Illuminate\Database\Eloquent\Model;
use tizis\achievements\Contracts\Achievement;
use tizis\achievements\Contracts\HasAchievements;

class AchievementService
{
protected Model $user;
protected HasAchievements $user;

public function __construct(Model $user)
public function __construct(HasAchievements $user)
{
$this->user = $user;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Services/GroupAchievementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace tizis\achievements\Services;

use Illuminate\Database\Eloquent\Model;
use tizis\achievements\Contracts\Group;
use tizis\achievements\Contracts\HasAchievements;

class GroupAchievementService
{
protected $user;
protected HasAchievements $user;

public function __construct(Model $user)
public function __construct(HasAchievements $user)
{
$this->user = $user;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use tizis\achievements\Contracts\Achievement;
use tizis\achievements\Contracts\Group;

trait Achievementable
trait InteractsWithAchievements
{
public function achievements(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
Expand Down

0 comments on commit 54bf7a1

Please sign in to comment.