As a fledgling programmer you’re bombarded by commandments telling you what’s considered right programming and wrong programming. These edicts can seem very useful and on the surface seem irrefutable. But if they are applied without deeper thought they can do more harm than good. One of the worst offenders is ‘thy code shalt have abundant comments’. Another questionable one is the DRY principle.
‘DRY’ is an acronym meaning: Don’t Repeat Yourself. It is often interpreted to mean there should be no similar blocks of code in a codebase. …
This article summaries a solution to the problem of calling and listing commands in Symfony Console when at least one of the commands is not instantiable.
By default, Symfony will instantiate all your application’s commands when initialising. If just one of the commands fails to initialize, the entire application will fail — even when executing a command that works fine.
Ordinarily, this shouldn’t be a problem. After all, classes should be instantiable, shouldn’t they? But, in my work at Funeral Zone, we have a use-case of a console application that sits in multiple microservices. Some of the commands in the application are reliant on environment variables (such as database credentials) that are not necessary for all microservices. …
Here’s an example of a composite value object. It’s a user that has two subtypes: an email address and a name.
final class User
private $name; public function getEmailAddress(): EmailAddress
} public function getName(): Name
} public function withName(Name $name): User
$native = $this->toNative();
$native['name'] = $name->toNative();
To mutate the name of a
User you take an existing object and call the
withName method on it. This method returns a new instance of
User where all the previous values are the same, but
name is now set to the new value. …