How can the code snippet be optimized to improve readability and avoid spaghetti code?

The code snippet can be optimized by breaking down the logic into smaller, more manageable functions with descriptive names. This will improve readability and maintainability of the code. Additionally, using comments to explain the purpose of each function or block of code can help others understand the code more easily.

<?php

// Function to calculate the total price
function calculateTotalPrice($quantity, $price) {
    return $quantity * $price;
}

// Function to check if the user is eligible for a discount
function isEligibleForDiscount($totalPrice) {
    if ($totalPrice > 100) {
        return true;
    } else {
        return false;
    }
}

// Main code
$quantity = 5;
$price = 20;

$totalPrice = calculateTotalPrice($quantity, $price);

if (isEligibleForDiscount($totalPrice)) {
    echo "You are eligible for a discount!";
} else {
    echo "You are not eligible for a discount.";
}

?>