PostDeleteByIdAction::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Finder\Http\Actions;
4
5
use Population\Manipule\Managers\PostManager;
6
use Illuminate\Contracts\Cache\Factory as CacheManager;
7
use Illuminate\Contracts\Routing\ResponseFactory;
8
use Illuminate\Http\JsonResponse;
9
10
/**
11
 * Class PostDeleteByIdAction.
12
 *
13
 * @package Finder\Http\Actions
14
 */
15
class PostDeleteByIdAction
16
{
17
    /**
18
     * @var ResponseFactory
19
     */
20
    private $responseFactory;
21
22
    /**
23
     * @var PostManager
24
     */
25
    private $postManager;
26
27
    /**
28
     * @var CacheManager
29
     */
30
    private $cacheManager;
31
32
    /**
33
     * PostDeleteByIdAction constructor.
34
     *
35
     * @param ResponseFactory $responseFactory
36
     * @param PostManager     $postManager
37
     * @param CacheManager    $cacheManager
38
     */
39
    public function __construct(ResponseFactory $responseFactory, PostManager $postManager, CacheManager $cacheManager)
40
    {
41
        $this->responseFactory = $responseFactory;
42
        $this->postManager = $postManager;
43
        $this->cacheManager = $cacheManager;
44
    }
45
46
    /**
47
     * @apiVersion        1.0.0
48
     * @api               {delete} /v1/posts/:post_id Delete
49
     * @apiName           Delete
50
     * @apiGroup          Posts
51
     * @apiHeader         {String} Accept application/json
52
     * @apiParam          {Integer{1..N}} :post_id Unique resource ID.
53
     * @apiSuccessExample {json} Success-Response:
54
     * HTTP/1.1 204 No Content
55
     */
56
57
    /**
58
     * Delete a post.
59
     *
60
     * @param  mixed $id
61
     * @return JsonResponse
62
     */
63
    public function __invoke($id): JsonResponse
64
    {
65
        $this->postManager->deleteById((int) $id);
66
67
        $this->cacheManager->tags(['posts', 'photos', 'tags'])->flush();
0 ignored issues
show
Bug introduced by
The method tags() does not seem to exist on object<Illuminate\Contracts\Cache\Factory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
69
        return $this->responseFactory->json(null, JsonResponse::HTTP_NO_CONTENT);
70
    }
71
}
72