public function withItem (MenuItem $item)
    {
        if (count($this->items) >= 3) {
            throw new LengthException("Maximum of 3 items allowed in a menu.");
        }

        $cloned = clone $this;
        $cloned->items[] = $item;

        return $cloned;
    }
public function withItem (MenuItem $item)
    {
        if (count($this->items) >= 3) {
            throw new LengthException("Maximum of 3 items allowed in a menu.");
        }

        $cloned = clone $this;
        $cloned->items[] = $item;

        return $cloned;
    }
public function withItem ( MenuItem $ item ) { if ( count ( $ this -> items ) >= 3 ) { throw new LengthException ( "Maximum of 3 items allowed in a menu." ) ; } $ cloned = clone $ this ; $ cloned -> items [ ] = $ item ; return $ cloned ; }
Adds a new item to the menu. Ensures the menu remains immutable.

@param MenuItem $item

@return Menu
Adds a new item to the menu . Ensures the menu remains immutable .