How do you create entities?

razbakov

Aleksey Razbakov

Posted on July 13, 2020

How do you create entities?

I recently discovered a code like this:

function createLead(
    $salutation,
    $firstName,
    $lastName,
    $email
) {
    $lead = new Lead();
    $lead->setSalutation($salutation);
    $lead->setFirstName($firstName);
    $lead->setLastName($lastName);
    $lead->setEmail($email);
}

It is painful for me to work with code like this, because adding a new field to an entity will require not only changes in entity, but everywhere where creation is triggered, and the worst part is that it's super easy to misplace the argument and have unexpected results.

Do you see any pattern/anti-pattern in this code? Would you consider that to be a good or bad practice? Would you refactor it?

💖 💪 🙅 🚩
razbakov
Aleksey Razbakov

Posted on July 13, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How do you create entities?
discuss How do you create entities?

July 13, 2020