Level 58
One possible solution is to use a ternary operator to simplify the code:
if ($this->orderByColumn == $column) {
$this->orderDirection = ($this->orderDirection == 'DESC') ? 'ASC' : 'DESC';
}
This code checks if the current orderByColumn is equal to the given $column. If it is, it sets the orderDirection to 'ASC' if it was 'DESC', and vice versa. The ternary operator is used to avoid the if/else statement and make the code more concise.
1 like