Re: Type variants

From: Date: Sun, 12 Mar 2017 09:58:27 +0000
Subject: Re: Type variants
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-98501@lists.php.net to get a copy of this message
On 3/12/2017 10:36 AM, Michael Vostrikov wrote: > Now we need to write in business logic the following: > > function checkout(Order $order) > { > if (count($order->products) > 0) { > throw new SomeException1(); > } > if ($order->date === null) { > throw new SomeException2(); > } > if ($order->address === null) { > throw new SomeException3(); > } > > // checkout steps > ... > someActionWithOrderForCheckout($order); > ... > } > > function someActionWithOrderForCheckout(Order $order) > { > if (count($order->products) > 0) { > ... > } > if () > ... > } > > > Of course, we can move all checks to some function like > 'ensureOrderIsReadyForCheckout()' and call it everywhere manually. > But this is the same as call is_integer() manually instead of type hinting. > The problem you are facing is that you are dealing with an anemic domain object that does not enforce its own invariants. Properly applying OOD principles would remedy all your problems. However, you do not require new features to do that. -- Richard "Fleshgrinder" Fussenegger

« previous php.internals (#98501) next »