Passed
Push — master ( ed3a21...c78a04 )
by Guido
06:24
created

UserStatuses   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
dl 0
loc 31
c 2
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 21 4
A index() 0 3 1
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
     */
32
    public function create()
33
    {
34
        $userService = $this->getUserService();
1 ignored issue
show
Bug introduced by
The method getUserService() does not exist on Gvera\Controllers\UserStatuses. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        /** @scrutinizer ignore-call */ 
35
        $userService = $this->getUserService();
Loading history...
35
        if (!$this->httpRequest->isPost()) {
36
            throw new InvalidHttpMethodException(
37
                'Http method used mismatch with expected',
38
                ['used' => $_SERVER['REQUEST_METHOD'], 'expected' => HttpRequest::POST]
39
            );
40
        }
41
42
        if (!$userService->isUserLoggedIn() ||
43
            $userService->getSessionUserRole() < $userService::MODERATOR_ROLE_PRIORITY
44
        ) {
45
            throw new Exception(Locale::getLocale('User must be logged in and have the correct rights'));
46
        }
47
48
        $newUserStatusCommand = new CreateUserStatusCommand(
49
            $this->httpRequest->getParameter('name'),
50
            $this->diContainer->get("entityManager")
51
        );
52
        $newUserStatusCommand->execute();
53
    }
54
}
55