Menu

PHPStan is green. Why is this code still hard to change?
📰

PHPStan is green. Why is this code still hard to change?

DEV Community: php·Alexandr·about 2 hours ago
#vDlNQBE7
#devto#dev#order#method#orders
Reading 0:00
15s threshold

Suppose you need to change when an order can ship. You open the method and find this:

final class ShipOrders { /** @param list<Order> $orders */ public function ship ( array $orders ) : void { foreach ( $orders as $order ) { if ( $order -> isPaid ( ) ) { if ( $order -> isReady ( ) ) { if ( $order -> hasAddress ( ) ) { $order -> ship ( ) ; } } } } } }

Enter fullscreen mode

Exit fullscreen mode

Assume the three questions return bool and ship() returns void . The types are consistent. Every call exists. PHPStan accepts this code, including at its highest built-in rule level.

Now add another requirement: orders on hold must wait.

You have to find the right place inside that staircase, understand which conditions have already run, and preserve what happens when one fails. None of this is particularly difficult.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.