How does maintaining consistency in function behavior contribute to code quality in PHP?

Maintaining consistency in function behavior in PHP helps improve code quality by making the code easier to understand, maintain, and debug. When functions consistently behave in a predictable manner, it reduces the chances of unexpected errors and makes it easier for other developers to work with the code.

function calculateTotal($price, $quantity) {
    if (!is_numeric($price) || !is_numeric($quantity)) {
        throw new InvalidArgumentException('Price and quantity must be numeric values.');
    }

    return $price * $quantity;
}