for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Services;
use App\Models\User;
use Carbon\Carbon;
use LaravelEnso\Helpers\Services\Decimals;
class ProfileBuilder
{
private const LoginRating = 80;
private const ActionRating = 20;
public function __construct(private readonly User $user)
}
public function set(): void
$this->user->load([
'person:id,name,appellative,birthday,phone',
'group:id,name', 'role:id,name', 'avatar:id,user_id',
]);
$this->build();
public function build(): void
$this->user->loginCount = $this->user->logins()->count();
loginCount
App\Models\User
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.
$this->user->actionLogCount = $this->user->actionLogs()->count();
actionLogCount
$this->user->daysSinceMember = max(Carbon::parse($this->user->created_at)->diffInDays(), 1);
daysSinceMember
$this->user->rating = $this->rating();
rating
private function rating(): int
$loginRatio = Decimals::div($this->user->loginCount, $this->user->daysSinceMember);
$loginRating = Decimals::mul(self::LoginRating, $loginRatio);
$actionRatio = Decimals::div($this->user->actionLogCount, $this->user->daysSinceMember);
$actionRating = Decimals::mul(self::ActionRating, $actionRatio);
$total = Decimals::add($loginRating, $actionRating);
return (int) Decimals::div($total, 100);
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.