Last active
February 4, 2026 12:48
-
-
Save mcsee/a6a0b099c28a609c2e48df811dc5294d to your computer and use it in GitHub Desktop.
This gist belongs to the Clean Code Cookbook https://cleancodecookbook.com by Maximiliano Contieri https://maximilianocontieri.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| /** @var User[] $users */ | |
| // this is a static declaration used by many IDEs but not the compiler | |
| // Like many comments it is useless, and possible outdated | |
| function notifyUsers(array $users) { | |
| foreach ($users as $user) { | |
| // You have no guarantee $user is actually a User object | |
| // The comment above is | |
| // just a hint for the IDE/Static Analysis | |
| $user->sendNotification(); | |
| } | |
| } | |
| $users = [new User('Anatoli Bugorski'), new Product('Laser')]; | |
| // This array is anemic and lacks runtime type enforcement | |
| // There's a Product in the collection and will show a fatal error | |
| // unless it can understand #sendNotification() method | |
| notifyUsers($users); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment