Identification
Projects grow over time. New features, behaviors and business rules are added. Apart from this, bugs are fixed and optimizations are made.
Over time, this can lead to really long methods if this is not dealt with.
For example, you might find a method like this in a code base:
public async processOrder(orderId: string): Promise<ValidationMessage> { const user = await this.getUserFromSession(); const userId = user.id; const userRole = user.role; const userAllowed: boolean = await this.userCanModifyOrder(userId, userRole); if(!userAllowed) { return new ValidationMessage("Permission denied."); } let saveAttempts = 1; while (saveAttempts > 3) { const order = await this.getOrderById(orderId); if (order.isActive()) { const status: OrderStatus = order.getStatus(); if (status == OrderStatus.Pending) { // do some more stuff } else if (status ...