Code Duplication    Length = 37-38 lines in 2 locations

src/Assembler/CategoryAssembler.php 2 locations

@@ 84-121 (lines=38) @@
81
     *
82
     * @return array The array with the categories
83
     */
84
    public function getCategoriesWithResolvedPath()
85
    {
86
87
        // prepare the categories
88
        $categories = array();
89
90
        // load the categories from the database
91
        $availableCategories = $this->categoryRepository->findAll();
92
93
        // create the array with the resolved category path as keys
94
        foreach ($availableCategories as $category) {
95
            // expload the entity IDs from the category path
96
            $entityIds =  $this->serializer->explode($category[MemberNames::PATH]);
97
98
            // cut-off the root category
99
            array_shift($entityIds);
100
101
            // continue with the next category if no entity IDs are available
102
            if (sizeof($entityIds) === 0) {
103
                continue;
104
            }
105
106
            // initialize the array for the path elements
107
            $path = array();
108
            foreach ($entityIds as $entityId) {
109
                $cat = $this->categoryVarcharRepository->findByEntityId($entityId);
110
                if ($cat && $cat[MemberNames::VALUE]) {
111
                    $path[] = $cat[MemberNames::VALUE];
112
                }
113
            }
114
115
            // append the catogory with the string path as key
116
            $categories[$this->serializer->implode($path)] = $category;
117
        }
118
119
        // return array with the categories
120
        return $categories;
121
    }
122
123
124
    /**
@@ 132-168 (lines=37) @@
129
     *
130
     * @return array The available categories for the passed store view ID
131
     */
132
    public function getCategoriesWithResolvedPathByStoreView($storeViewId)
133
    {
134
        // prepare the categories
135
        $categories = array();
136
137
        // load the categories from the database
138
        $availableCategories = $this->categoryRepository->findAllByStoreView($storeViewId);
139
140
        // create the array with the resolved category path as keys
141
        foreach ($availableCategories as $category) {
142
            // expload the entity IDs from the category path
143
            $entityIds = $this->serializer->explode($category[MemberNames::PATH]);
144
145
            // cut-off the root category
146
            array_shift($entityIds);
147
148
            // continue with the next category if no entity IDs are available
149
            if (sizeof($entityIds) === 0) {
150
                continue;
151
            }
152
153
            // initialize the array for the path elements
154
            $path = array();
155
            foreach ($entityIds as $entityId) {
156
                $cat = $this->categoryVarcharRepository->findByEntityId($entityId);
157
                if ($cat && $cat[MemberNames::VALUE]) {
158
                    $path[] = $cat[MemberNames::VALUE];
159
                }
160
            }
161
162
            // append the catogory with the string path as key
163
            $categories[$this->serializer->implode($path)] = $category;
164
        }
165
166
        // return array with the categories
167
        return $categories;
168
    }
169
}
170