dazzz1er / confer

Easy real-time chat for laravel 5 based websites and applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pointless if else in Message Class for getEventData

ericp1337 opened this issue · comments

why is there an if else statement here when both arrays are the same data?

public function getEventData($type = 'private')
    {
        return $type === 'global' ? [
            'conversation' => $this->conversation,
            'message' => $this,
            'sender' => $this->sender
        ] : [
            'conversation' => $this->conversation,
            'message' => $this,
            'sender' => $this->sender
        ];
    }

It's one of those cases where I believe I was originally supplying different data for the conversation types, and when it eventually came about that they send the same data I decided to leave the statement in, as future upgrades to the package will likely force the if else to appear again.

You could definitely argue it is inefficient, wasteful code, and I would agree... but I like the reminder that this is where I can - and where I intend to - differentiate the data in future. It's a form of forward planning for me.