Completed
Pull Request — master (#114)
by Beñat
09:39
created

OrganizationController::postOrganizationsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\OrganizationBundle\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 Organization;
19
use Kreta\SimpleApiDocBundle\Annotation\ApiDoc;
20
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * Organization controller class.
25
 *
26
 * @author Beñat Espiña <[email protected]>
27
 */
28
class OrganizationController extends Controller
29
{
30
    /**
31
     * Returns all the organizations of current user, it admits sort, limit and offset.
32
     *
33
     * @param ParamFetcher $paramFetcher The param fetcher
34
     *
35
     * @QueryParam(name="limit", requirements="\d+", default="9999", description="Amount of orgs to be returned")
36
     * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset in pages")
37
     *
38
     * @ApiDoc(resource=true, statusCodes={200})
39
     * @View(statusCode=200, serializerGroups={"organizationList"})
40
     *
41
     * @return \Kreta\Component\Organization\Model\Interfaces\OrganizationInterface[]
42
     */
43 View Code Duplication
    public function getOrganizationsAction(ParamFetcher $paramFetcher)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        return $this->get('kreta_organization.repository.organization')->findByParticipant(
46
            $this->getUser(),
47
            ['name' => 'ASC'],
48
            $paramFetcher->get('limit'),
49
            $paramFetcher->get('offset')
50
        );
51
    }
52
53
    /**
54
     * Returns the organization for given id.
55
     *
56
     * @param Request $request        The request
57
     * @param string  $organizationId The id of organization
58
     *
59
     * @ApiDoc(statusCodes={200, 403, 404})
60
     * @View(statusCode=200, serializerGroups={"organization"})
61
     * @Organization()
62
     *
63
     * @return \Kreta\Component\Organization\Model\Interfaces\OrganizationInterface
64
     */
65
    public function getOrganizationAction(Request $request, $organizationId)
0 ignored issues
show
Unused Code introduced by
The parameter $organizationId 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...
66
    {
67
        return $request->get('organization');
68
    }
69
70
    /**
71
     * Creates new organization for name given.
72
     *
73
     * @param Request $request The request
74
     *
75
     * @ApiDoc(statusCodes={201, 400})
76
     * @View(statusCode=201, serializerGroups={"organization"})
77
     *
78
     * @return \Kreta\Component\Organization\Model\Interfaces\OrganizationInterface
79
     */
80
    public function postOrganizationsAction(Request $request)
81
    {
82
        return $this->get('kreta_organization.form_handler.organization')->processForm($request);
83
    }
84
85
    /**
86
     * Updates the organization of id given.
87
     *
88
     * @param Request $request        The request
89
     * @param string  $organizationId The organization id
90
     *
91
     * @ApiDoc(statusCodes={200, 400, 403, 404})
92
     * @View(statusCode=200, serializerGroups={"organization"})
93
     * @Organization("edit")
94
     *
95
     * @return \Kreta\Component\Organization\Model\Interfaces\OrganizationInterface
96
     */
97
    public function putOrganizationsAction(Request $request, $organizationId)
0 ignored issues
show
Unused Code introduced by
The parameter $organizationId 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...
98
    {
99
        return $this->get('kreta_organization.form_handler.organization')->processForm(
100
            $request, $request->get('organization'), ['method' => 'PUT']
101
        );
102
    }
103
104
    /**
105
     * Returns all the projects of given organization, it admits limit and offset.
106
     *
107
     * @param Request      $request        The request
108
     * @param ParamFetcher $paramFetcher   The param fetcher
109
     * @param string       $organizationId The organization id
110
     *
111
     * @QueryParam(name="limit", requirements="\d+", default="9999", description="Amount of projects to be returned")
112
     * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset in pages")
113
     *
114
     * @ApiDoc(statusCodes={200, 403, 404})
115
     * @View(statusCode=200, serializerGroups={"projectList"})
116
     * @Organization()
117
     *
118
     * @return \Kreta\Component\Project\Model\Interfaces\ProjectInterface[]
119
     */
120 View Code Duplication
    public function getOrganizationProjectsAction(Request $request, ParamFetcher $paramFetcher, $organizationId)
0 ignored issues
show
Unused Code introduced by
The parameter $organizationId 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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122
        return $this->get('kreta_project.repository.project')->findByParticipant(
123
            $this->getUser(),
124
            $request->get('organization'),
125
            ['name' => 'ASC'],
126
            $paramFetcher->get('limit'),
127
            $paramFetcher->get('offset')
128
        );
129
    }
130
}
131