Completed
Push — master ( 00cd39...47d74e )
by Tom
05:36
created

VoteController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A castVoteAction() 0 18 3
1
<?php
2
namespace Kineo\Controller;
3
4
use Silex\Application;
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Kineo\Component\Database;
8
use Kineo\Component\ApiResponse;
9
use Kineo\Model\UserModel;
10
11
class VoteController
12
{	
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
13
	public function castVoteAction() 
14
	{
15
		$userData = json_decode(file_get_contents('php://input'));
16
		
17
		$userModel = new UserModel(new Database());
18
		
19
		if($userModel->loadUserByEmail($userData->email)) {
20
			return ApiResponse::error('USER_EXISTS');
21
		}
22
		
23
		try {	
24
			$userModel->saveUser($userData->email, $userData->first_name, $userData->surname, $userData->constituency, $userData->voting, $userData->candidate);
25
			
26
			return ApiResponse::success('DEFAULT_RESPONSE_SUCCESS');
27
		} catch(\Exception $e) {
28
			return ApiResponse::error('USER_SAVE_FAIL');
29
		}		
30
	}
31
}