UserStatuses   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 3
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 3 1
A create() 0 22 3
1
<?php
2
namespace Gvera\Controllers;
3
4
use Exception;
5
use Gvera\Commands\CreateUserStatusCommand;
6
use Gvera\Exceptions\InvalidHttpMethodException;
7
use Gvera\Helpers\http\HttpRequest;
8
use Gvera\Helpers\http\Response;
9
use Gvera\Helpers\locale\Locale;
10
use Gvera\Services\UserService;
11
12
/**
13
 * Controller Class Doc Comment
14
 *
15
 * @category Class
16
 * @package  src/controllers
17
 * @author    Guido Vera
18
 * @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
19
 * @link     http://www.github.com/veraguido/gv
20
 *
21
 */
22
class UserStatuses extends GvController
23
{
24
    public function index()
25
    {
26
        $this->httpResponse->response(new Response('userstatuses'));
27
    }
28
29
    /**
30
     * @throws Exception
31
     * @httpMethod("POST")
32
     */
33
    public function create()
34
    {
35
        $userService = $this->getUserService();
36
37
        if (!$userService->isUserLoggedIn() ||
38
            $userService->getSessionUserRole() < $userService::MODERATOR_ROLE_PRIORITY
39
        ) {
40
            $this->httpResponse->response(
41
                new Response(
42
                    Locale::getLocale('User must be logged in and have the correct rights'),
43
                    Response::CONTENT_TYPE_PLAIN_TEXT,
44
                    Response::HTTP_RESPONSE_UNAUTHORIZED
45
                )
46
            );
47
            return;
48
        }
49
50
        $newUserStatusCommand = new CreateUserStatusCommand(
51
            $this->httpRequest->getParameter('name'),
52
            $this->diContainer->get("entityManager")
53
        );
54
        $newUserStatusCommand->execute();
55
    }
56
}
57