Code Duplication    Length = 38-39 lines in 2 locations

api/CategoriesApi.php 1 location

@@ 7-45 (lines=39) @@
4
use Bedard\Shop\Models\ApiSettings;
5
use Bedard\Shop\Repositories\CategoryRepository;
6
7
class CategoriesApi extends ApiController
8
{
9
    /**
10
     * List categories.
11
     *
12
     * @param  CategoryRepository               $repository
13
     * @return October\Rain\Database\Collection
14
     */
15
    public function index(CategoryRepository $repository)
16
    {
17
        $query = input();
18
        $options = ApiSettings::getCategoriesOptions();
19
20
        if (! $options['is_enabled']) {
21
            return abort(403, 'Forbidden');
22
        }
23
24
        return $repository->get($query, $options);
25
    }
26
27
    /**
28
     * Find a category.
29
     *
30
     * @param  CategoryRepository           $repository
31
     * @param  string                       $slug
32
     * @return \Bedard\Shop\Models\Category
33
     */
34
    public function show(CategoryRepository $repository, $slug)
35
    {
36
        $query = input();
37
        $options = ApiSettings::getCategoryOptions();
38
39
        if (! $options['is_enabled']) {
40
            return abort(403, 'Forbidden');
41
        }
42
43
        return $repository->find($slug, $query, $options);
44
    }
45
}
46

api/ProductsApi.php 1 location

@@ 7-44 (lines=38) @@
4
use Bedard\Shop\Models\ApiSettings;
5
use Bedard\Shop\Repositories\ProductRepository;
6
7
class ProductsApi extends ApiController
8
{
9
    /**
10
     * List products.
11
     *
12
     * @return October\Rain\Database\Collection
13
     */
14
    public function index(ProductRepository $repository)
15
    {
16
        $query = input();
17
        $options = ApiSettings::getProductsOptions();
18
19
        if (! $options['is_enabled']) {
20
            return abort(403, 'Forbidden');
21
        }
22
23
        return $repository->get($query, $options);
24
    }
25
26
    /**
27
     * Find a product.
28
     *
29
     * @param  ProductRepository            $repository
30
     * @param  string                       $slug
31
     * @return \Bedard\Shop\Models\Product
32
     */
33
    public function show(ProductRepository $repository, $slug)
34
    {
35
        $query = input();
36
        $options = ApiSettings::getProductOptions();
37
38
        if (! $options['is_enabled']) {
39
            return abort(403, 'Forbidden');
40
        }
41
42
        return $repository->find($slug, $query, $options);
43
    }
44
}
45