Passed
Pull Request — main (#62)
by
unknown
02:54
created

AuthorAction::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 19
rs 9.7998
cc 2
nc 2
nop 2
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Controllers\Actions\Author;
4
5
use Botble\ACL\Models\User;
0 ignored issues
show
Bug introduced by
The type Botble\ACL\Models\User 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 Botble\Base\Http\Responses\BaseHttpResponse;
0 ignored issues
show
Bug introduced by
The type Botble\Base\Http\Responses\BaseHttpResponse 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...
7
use CSlant\Blog\Api\Http\Resources\AuthorWithPostResource;
8
use CSlant\Blog\Core\Http\Controllers\Base\BasePostController;
9
use Illuminate\Http\JsonResponse;
10
use Illuminate\Http\RedirectResponse;
11
use Illuminate\Http\Request;
12
use Illuminate\Http\Resources\Json\JsonResource;
13
14
/**
15
 * Class ViewCountAction
16
 *
17
 *
18
 * @group Blog API
19
 *
20
 * @authenticated
21
 *
22
 * @method BaseHttpResponse httpResponse()
23
 * @method BaseHttpResponse setData(mixed $data)
24
 * @method BaseHttpResponse|JsonResource|JsonResponse|RedirectResponse toApiResponse()
25
 */
26
class AuthorAction extends BasePostController
27
{
28
    /**
29
     * @param  int  $authorId
30
     *
31
     * @group Blog
32
     *
33
     * @queryParam  Find by authorId of user.
34
     *
35
     * @return BaseHttpResponse|JsonResource|JsonResponse|RedirectResponse
36
     */
37
    public function __invoke(int $authorId, Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse
38
    {
39
        $user = User::query()
40
            ->with('posts')
41
            ->whereId($authorId)
42
            ->first();
43
44
        if (!$user) {
45
            return $this
46
                ->httpResponse()
47
                ->setError()
48
                ->setCode(404)
49
                ->setMessage('Not found');
50
        }
51
52
        return $this
53
            ->httpResponse()
54
            ->setData(new AuthorWithPostResource($user))
55
            ->toApiResponse();
56
    }
57
}
58