From 10abc3ec9915f7fa104236dfbf0771e332babd6b Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Thu, 10 Sep 2026 20:39:51 -0400 Subject: [PATCH] refactor(auth): use tick() helper instead of manual Date instantiation Replace (new Date())->tick() with the tick() helper function to simplify date handling and reduce boilerplate code. This also allows for the removal of unused Leaf\Date imports across the Auth, Model, and User classes. --- src/Auth.php | 6 +++--- src/Auth/Model.php | 5 ++--- src/Auth/User.php | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 5f77c10..7addeae 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -371,7 +371,7 @@ public function register(array $userData): bool } if (Config::get('timestamps')) { - $now = (new Date())->tick()->format(Config::get('timestamps.format')); + $now = tick()->format(Config::get('timestamps.format')); $userData['created_at'] = $now; $userData['updated_at'] = $now; } @@ -435,7 +435,7 @@ public function update(array $userData): bool $table = Config::get('db.table'); if (Config::get('timestamps')) { - $userData['updated_at'] = (new Date())->tick()->format(Config::get('timestamps.format')); + $userData['updated_at'] = tick()->format(Config::get('timestamps.format')); } if (isset($userData['email'])) { @@ -623,7 +623,7 @@ public function createUserFor($userData) } if (Config::get('timestamps')) { - $now = (new Date())->tick()->format(Config::get('timestamps.format')); + $now = tick()->format(Config::get('timestamps.format')); $userData['created_at'] = $now; $userData['updated_at'] = $now; } diff --git a/src/Auth/Model.php b/src/Auth/Model.php index c5cc61d..d36a8bf 100644 --- a/src/Auth/Model.php +++ b/src/Auth/Model.php @@ -2,7 +2,6 @@ namespace Leaf\Auth; -use Leaf\Date; use Leaf\Db; use PDOStatement; @@ -56,7 +55,7 @@ public function create(array $data): ?PDOStatement $data['user_id'] = $this->user->id(); if (Config::get('timestamps')) { - $now = (new Date())->tick()->format(Config::get('timestamps.format')); + $now = tick()->format(Config::get('timestamps.format')); $data['created_at'] = $now; $data['updated_at'] = $now; } @@ -73,7 +72,7 @@ public function create(array $data): ?PDOStatement */ public function update(array $data): Db { - $data['updated_at'] = (new Date())->tick()->format(Config::get('timestamps.format')); + $data['updated_at'] = tick()->format(Config::get('timestamps.format')); return $this->db->update($this->table) ->params($data) diff --git a/src/Auth/User.php b/src/Auth/User.php index 63a60d8..5428d73 100644 --- a/src/Auth/User.php +++ b/src/Auth/User.php @@ -7,7 +7,6 @@ use ReturnTypeWillChange; use Leaf\Db; use Firebase\JWT\JWT; -use Leaf\Date; use Leaf\Helpers\Password; use Leaf\Http\Session; @@ -154,7 +153,7 @@ public function update(array $userData): bool $table = Config::get('db.table'); if (Config::get('timestamps')) { - $userData['updated_at'] = (new Date())->tick()->format(Config::get('timestamps.format')); + $userData['updated_at'] = tick()->format(Config::get('timestamps.format')); } if (isset($userData['email'])) {