Code Duplication    Length = 56-56 lines in 2 locations

src/Charcoal/Cms/Service/Manager/EventManager.php 1 location

@@ 299-354 (lines=56) @@
296
     * @param array $options The options for the collection loader.
297
     * @throws Exception When featured news ident is not valid.
298
     */
299
    public function featList(array $options = [])
300
    {
301
        if ($this->featList) {
302
            return $this->featList;
303
        }
304
305
        $loader = $this->loader()->published();
306
        $ident = $this->featIdent();
307
        $config = $this->adminConfig();
308
309
        if (!$ident || !method_exists($config, $ident)) {
310
            throw new Exception(sprintf(
311
                'The featured news ident "%s" doesn\'t exist the class "%s"',
312
                $ident,
313
                get_class($config)
314
            ));
315
        }
316
        $ids = $config->{$ident}();
317
318
        if (!$ids) {
319
            return null;
320
        }
321
322
        $ids = explode(',', $ids);
323
324
        $loader->addFilter('id', $ids, [ 'operator' => 'in' ])
325
            ->addOrder('id', 'values', [ 'values' => $ids ]);
326
327
        if (count($options) > 0) {
328
            foreach ($options as $key => $option) {
329
                switch ($key) {
330
                    case 'filters':
331
                        $filters = $option;
332
                        foreach ($filters as $f) {
333
                            $filter[] = $f['property'] ?: '';
334
                            $filter[] = $f['val'] ?: '';
335
                            $filter[] = $f['options'] ?: '';
336
                            $filter = join(',', $filter);
337
338
                            $loader->addFilter($filter);
339
                        }
340
                        break;
341
                    case 'page':
342
                        $loader->setPage($option);
343
                        break;
344
                    case 'numPerPage':
345
                        $loader->setNumPerPage($option);
346
                        break;
347
                }
348
            }
349
        }
350
351
        $this->featList = $loader->load();
352
353
        return $this->featList;
354
    }
355
356
    /**
357
     * @return EventInterface[]|Collection

src/Charcoal/Cms/Service/Manager/NewsManager.php 1 location

@@ 201-256 (lines=56) @@
198
     * @param array $options The options for the collection loader.
199
     * @throws Exception When featured news ident is not valid.
200
     */
201
    public function featList(array $options = [])
202
    {
203
        if ($this->featList) {
204
            return $this->featList;
205
        }
206
207
        $loader = $this->loader()->published();
208
        $ident = $this->featIdent();
209
        $config = $this->adminConfig();
210
211
        if (!$ident || !method_exists($config, $ident)) {
212
            throw new Exception(sprintf(
213
                'The featured news ident "%s" doesn\'t exist the class "%s"',
214
                $ident,
215
                get_class($config)
216
            ));
217
        }
218
        $ids = $config->{$ident}();
219
220
        if (!$ids) {
221
            return null;
222
        }
223
224
        $ids = explode(',', $ids);
225
226
        $loader->addFilter('id', $ids, [ 'operator' => 'in' ])
227
            ->addOrder('id', 'values', [ 'values' => $ids ]);
228
229
        if (count($options) > 0) {
230
            foreach ($options as $key => $option) {
231
                switch ($key) {
232
                    case 'filters':
233
                        $filters = $option;
234
                        foreach ($filters as $f) {
235
                            $filter[] = $f['property'] ?: '';
236
                            $filter[] = $f['val'] ?: '';
237
                            $filter[] = $f['options'] ?: '';
238
                            $filter = join(',', $filter);
239
240
                            $loader->addFilter($filter);
241
                        }
242
                        break;
243
                    case 'page':
244
                        $loader->setPage($option);
245
                        break;
246
                    case 'numPerPage':
247
                        $loader->setNumPerPage($option);
248
                        break;
249
                }
250
            }
251
        }
252
253
        $this->featList = $loader->load();
254
255
        return $this->featList;
256
    }
257
258
    /**
259
     * @return NewsInterface[]|Collection