Passed
Push — main ( 18250b...f71c86 )
by Tan
02:53 queued 25s
created

CategoryController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 24
c 0
b 0
f 0
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A findBySlug() 0 32 3
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Controllers;
4
5
use Botble\Blog\Http\Resources\ListCategoryResource;
0 ignored issues
show
Bug introduced by
The type Botble\Blog\Http\Resources\ListCategoryResource was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use CSlant\Blog\Api\Enums\StatusEnum;
7
use CSlant\Blog\Core\Facades\Base\SlugHelper;
8
use CSlant\Blog\Core\Http\Controllers\Base\BaseCategoryController;
9
use CSlant\Blog\Core\Models\Category;
10
11
class CategoryController extends BaseCategoryController
12
{
13
    /**
14
     * Get category by slug
15
     *
16
     * @group Blog
17
     * @queryParam slug Find by slug of category.
18
     */
19
    public function findBySlug(string $slug)
20
    {
21
        $slug = SlugHelper::getSlug($slug, SlugHelper::getPrefix(Category::getBaseModel()));
22
23
        if (! $slug) {
24
            return $this
25
                ->httpResponse()
26
                ->setError()
27
                ->setCode(404)
28
                ->setMessage('Not found');
29
        }
30
31
        $category = Category::query()
32
            ->with('slugable')
33
            ->where([
34
                'id' => $slug->reference_id,
35
                'status' => StatusEnum::PUBLISHED,
36
            ])
37
            ->first();
38
39
        if (! $category) {
40
            return $this
41
                ->httpResponse()
42
                ->setError()
43
                ->setCode(404)
44
                ->setMessage('Not found');
45
        }
46
47
        return $this
48
            ->httpResponse()
49
            ->setData(new ListCategoryResource($category))
50
            ->toApiResponse();
51
    }
52
}
53