CommentController::putCommentsAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 2
Metric Value
c 6
b 0
f 2
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Kreta\Bundle\CommentBundle\Controller;
14
15
use FOS\RestBundle\Controller\Annotations\QueryParam;
16
use FOS\RestBundle\Controller\Annotations\View;
17
use FOS\RestBundle\Request\ParamFetcher;
18
use Kreta\Component\Core\Annotation\ResourceIfAllowed as Issue;
19
use Kreta\SimpleApiDocBundle\Annotation\ApiDoc;
20
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * Comment controller class.
25
 *
26
 * @author Beñat Espiña <[email protected]>
27
 * @author Gorka Laucirica <[email protected]>
28
 */
29
class CommentController extends Controller
30
{
31
    /**
32
     * Returns all comments of issue id given, it admits date and owner filters, limit and offset.
33
     *
34
     * @param \Symfony\Component\HttpFoundation\Request $request      The request
35
     * @param string                                    $issueId      The issue id
36
     * @param \FOS\RestBundle\Request\ParamFetcher      $paramFetcher The param fetcher
37
     *
38
     * @QueryParam(name="owner", requirements="(.*)", strict=true, nullable=true, description="Owner's email filter")
39
     * @QueryParam(name="createdAt", requirements="(.*)", strict=true, nullable=true, description="Created at filter")
40
     * @QueryParam(name="limit", requirements="\d+", default="9999", description="Amount of comments to be returned")
41
     * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset in pages")
42
     *
43
     * @ApiDoc(resource=true, statusCodes = {200, 403, 404})
44
     * @View(statusCode=200, serializerGroups={"commentList"})
45
     * @Issue()
46
     *
47
     * @return \Kreta\Component\Comment\Model\Interfaces\CommentInterface[]
48
     */
49
    public function getCommentsAction(Request $request, $issueId, ParamFetcher $paramFetcher)
0 ignored issues
show
Unused Code introduced by
The parameter $issueId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        return $this->get('kreta_comment.repository.comment')->findByIssue(
52
            $request->get('issue'),
53
            $paramFetcher->get('createdAt') ? new \DateTime($paramFetcher->get('createdAt')) : null,
54
            $paramFetcher->get('owner'),
55
            $paramFetcher->get('limit'),
56
            $paramFetcher->get('offset')
57
        );
58
    }
59
60
    /**
61
     * Creates new comment for description given.
62
     *
63
     * @param \Symfony\Component\HttpFoundation\Request $request The request
64
     * @param string                                    $issueId The issue id
65
     *
66
     * @ApiDoc(statusCodes={201, 400, 403, 404})
67
     * @View(statusCode=201, serializerGroups={"comment"})
68
     * @Issue()
69
     *
70
     * @return \Kreta\Component\Comment\Model\Interfaces\CommentInterface
71
     */
72
    public function postCommentsAction(Request $request, $issueId)
0 ignored issues
show
Unused Code introduced by
The parameter $issueId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
    {
74
        return $this->get('kreta_comment.form_handler.comment')->processForm(
75
            $request, null, ['issue' => $request->get('issue')]
76
        );
77
    }
78
79
    /**
80
     * Updates the comment of issue id and comment id given.
81
     *
82
     * @param \Symfony\Component\HttpFoundation\Request $request   The request
83
     * @param string                                    $issueId   The issue id
84
     * @param string                                    $commentId The comment id
85
     *
86
     * @ApiDoc(statusCodes={200, 400, 403, 404})
87
     * @View(statusCode=200, serializerGroups={"comment"})
88
     * @Issue()
89
     *
90
     * @return \Kreta\Component\Comment\Model\Interfaces\CommentInterface
91
     */
92
    public function putCommentsAction(Request $request, $issueId, $commentId)
0 ignored issues
show
Unused Code introduced by
The parameter $issueId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        $comment = $this->get('kreta_comment.repository.comment')->findByUser($commentId, $this->getUser());
95
96
        return $this->get('kreta_comment.form_handler.comment')->processForm(
97
            $request, $comment, ['method' => 'PUT', 'issue' => $request->get('issue')]
98
        );
99
    }
100
}
101