Passed
Pull Request — master (#53)
by Matthew
02:43
created

UserProfileController::InviteNewCommissioner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 18
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace PhpDraft\Controllers\Commish;
4
5
use \Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use PhpDraft\Domain\Models\UserProfile;
9
use PhpDraft\Domain\Entities\LoginUser;
10
use PhpDraft\Domain\Models\PhpDraftResponse;
11
12
class UserProfileController {
13
  public function Get(Application $app, Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

13
  public function Get(Application $app, /** @scrutinizer ignore-unused */ Request $request) {

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

Loading history...
14
    $user = $app['phpdraft.LoginUserService']->GetCurrentUser();
15
16
    if (empty($user)) {
17
      return $app->json(new PhpDraftResponse(false));
18
    }
19
20
    return $app->json(new UserProfile($user->id, $user->email, $user->name), Response::HTTP_OK);
21
  }
22
23
  public function Put(Application $app, Request $request) {
24
    $validity = $app['phpdraft.LoginUserValidator']->IsUserProfileUpdateValid($request);
25
26
    if (!$validity->success) {
27
      return $app->json($validity, Response::HTTP_BAD_REQUEST);
28
    }
29
30
    $response = $app['phpdraft.LoginUserService']->UpdateUserProfile($request);
31
32
    return $app->json($response, $response->responseType());
33
  }
34
35
  public function InviteNewCommissioner(Application $app, Request $request) {
36
    $user = new LoginUser();
37
38
    $user->enabled = 0;
39
    $user->email = $request->get('email');
40
    $user->name = $request->get('name');
41
42
    $message = $request->get('message');
43
44
    $validity = $app['phpdraft.LoginUserValidator']->isInviteNewUserValid($user, $message);
45
46
    if (!$validity->success) {
47
      return $app->json($validity, $validity->responseType());
48
    }
49
50
    $response = $app['phpdraft.UsersService']->InviteNewUser($user, $message);
51
52
    return $app->json($response, $response->responseType());
53
  }
54
}
55