mercredi 27 mars 2019

What are the effects after making non-chainable setter chainable?

I have the following class.

<?php

namespace CompanyName\DataBundle\Entity\Intern;
class Order 
{
    public function __construct($invoiceAddress){
        $this->invoiceAddress = $invoiceAddress;
    }
    //non-chainable setter
    public function setInvoiceAddress(Address $invoiceAddress)
    {
        $this->invoiceAddress = $invoiceAddress;       
    }
}

Now I want to make the setter (setInvoiceAddress) chainable. So I made the following changes to the function.

//chainable setter
public function setInvoiceAddress(Address $invoiceAddress)
{
    $this->invoiceAddress = $invoiceAddress;
    return $this;       
}

QUESTION: I want to know if the changes are correct and will work when chaining methods.

I have taken example from here.

Aucun commentaire:

Enregistrer un commentaire