$attributes */ protected static function fromArray(array $attributes): static { $user = new static(); $user->id = (int) $attributes['id']; $user->role = (string) $attributes['role']; $user->name = (string) $attributes['name']; $user->email = (string) $attributes['email']; $user->pass_hash = (string) $attributes['pass_hash']; $user->phone = $attributes['phone'] ?? null; $user->address = $attributes['address'] ?? null; $user->customer_id = isset($attributes['customer_id']) ? (int) $attributes['customer_id'] : null; $user->is_active = (bool) $attributes['is_active']; $user->twofa_secret = $attributes['twofa_secret'] ?? null; $user->created_at = (string) $attributes['created_at']; $user->updated_at = (string) $attributes['updated_at']; return $user; } public static function findByEmail(string $email): ?self { $stmt = \App\Core\Database::connection()->prepare('SELECT * FROM users WHERE email = :email LIMIT 1'); $stmt->execute(['email' => $email]); $row = $stmt->fetch(); if (!$row) { return null; } return self::fromArray($row); } }