Hi Sebastian,

sob., 14 wrz 2019 o 11:05 Sebastian Bergmann <sebast...@php.net> napisał(a):

> Am 13.09.2019 um 15:23 schrieb Matthew Brown:
> > Though this is truly a stylistic complaint, I think it will lead to
> > harder-to-analyse code.
>
> Fully agreed, and not just harder-to-analyse for a static analysis tool
> but also for humans that read the code. -1 from me.
>
>
Could you explain why additional noise caused by constantly repeating
instance variable name and arrow in front of property name and assignment
part
is easier to read? Just wondering why you see object initializer as harder
to read which I've view as easier to read.

Example - easy to read:
function createCustomerDTO(): Customer
{
    $customer = new Customer();
    $customer->id = Uuid::uuid4;
    $customer->name = "John Doe";
    $customer->address = "Customer Street 16";
    $customer->city = "London";
    $customer->country = "GB";
    $customer->phoneNumber = PhoneNumber::fromString("+1555 010 020");
    $customer->birthDate = new DateTimeImmutable("1983-01-01");
    $customer->email = Email::fromString("john....@example.com");

    return $customer;
}

Example - hard to read: Why?
function createCustomerDTO(): Customer
{
    return new Customer {
        id = Uuid::uuid4,
        name = "John Doe",
        address = "Customer Street 16",
        city = "London",
        country = "GB",
        phoneNumber = PhoneNumber::fromString("+1555 010 020"),
        birthDate = new DateTimeImmutable("1983-01-01"),
        email = Email::fromString("john....@example.com"),
    };
}

Thanks in advance,
Michał Brzuchalski

Reply via email to