HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/app/KommaApp/Shop/Menus/Menu.php
<?php


namespace KommaApp\Shop\menus;

use Illuminate\Routing\Router;

class Menu
{
    /**
     * @var MenuRepository
     */
    protected $menuRepository;

    /**
     * @var Router
     */
    protected $router;

    /**
     * @var Int
     */
    protected $languageId;

    /**
     * @var Int
     */
    protected $shopId;

    /**
     * @var array
     */
    protected $routeData;

    /**
     * @var Array
     */
    protected $menuItems;


    /**
     * @param MenuRepository $menuRepository
     * @param Router $router
     */
    public function __construct(MenuRepository $menuRepository, Router $router)
    {
        $this->menuRepository = $menuRepository;
        $this->router = $router;
    }

    /**
     * @param mixed $shopId
     */
    public function setShopId($shopId)
    {
        $this->shopId = $shopId;
    }

    /**
     * @param mixed $languageId
     */
    public function setLanguageId($languageId)
    {
        $this->languageId = $languageId;
    }

    /**
     * @param $currentRoutableId
     */
    public function setRouteData($routeData)
    {
        $this->routeData = $routeData;
    }

    /**
     * @param array $items
     * @param string $keyType
     * @return array
     */
    protected function stripDoubleRoutes(array $items, $keyType = 'id')
    {
        $menuItems = [];
        $checkForRoutes = [];

        foreach($items as $item)
        {
            $addItem = true;

            // If this item already exists with a different route
            if(isset($checkForRoutes[$item->{$keyType}]))
            {
                $addItem = false;
                $existingRoute = $checkForRoutes[$item->{$keyType}];

                // Always make sure the shortest route is added to the array
                if(strlen($item->route) < strlen($existingRoute))
                {
                    $addItem = true;
                }
            }
            // Do we need to add / update this item to the array?
            if($addItem)
            {
                $menuItems[$item->{$keyType}] = $item;

                // Also update the array $checkForRoutes
                $checkForRoutes[$item->{$keyType}] = $item->route;
            }
        }

        return $menuItems;
    }
}