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

DataController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 4
c 7
b 0
f 1
lcom 0
cbo 4
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchConstituenciesAction() 0 10 2
A fetchCandidatesAction() 0 10 2
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\ConstituenciesModel;
10
use Kineo\Model\CandidatesModel;
11
12
class DataController
13
{	
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
14
	public function fetchConstituenciesAction()
15
	{		
16
		$constituenciesModel = new ConstituenciesModel(new Database());
17
		
18
		if($constituenciesModel->getAllConstituencies()) {
19
			return json_encode($constituenciesModel->constituencies);
20
		} else {
21
			return ApiResponse::error('NO_CONSTITUENCIES_FOUND');	
22
		}
23
	}
24
	
25
	public function fetchCandidatesAction($constituencyId) 
26
	{
27
		$candidatesModel = new CandidatesModel(new Database());
28
		
29
		if($candidatesModel->getCandidatesByConstituencyId($constituencyId)) {
30
			return json_encode($candidatesModel->candidates);
31
		} else {
32
			return ApiResponse::error('NO_CANDIDATES_FOUND');	
33
		}
34
	}
35
}