ResultsModel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 2
dl 35
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A getResults() 23 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Kineo\Model;
3
4
use Kineo\Component\Database;
5
6 View Code Duplication
class ResultsModel extends BaseModel 
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
{
8
	protected $db;
9
	
10
	public $results = array();
11
	
12
	public function __construct(Database $db)
13
	{
14
		$this->db = $db;
15
	}
16
	
17
	public function getResults() 
18
	{
19
		$stmt = $this->db->query(
20
			"SELECT a.name, a.party, a.constituency_id, c.name AS constituency, COUNT(*) AS count 
21
			FROM tblCandidates AS a
22
			INNER JOIN tblVotes AS b
23
			ON a.id = b.candidate_id
24
			LEFT JOIN tblConstituencies AS c
25
			ON a.constituency_id = c.id
26
			GROUP BY b.candidate_id
27
			ORDER BY count DESC, constituency ASC"
28
		);
29
		
30
		$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
31
		
32
		if(is_array($result) && !empty($result)) {
33
			$this->results = $result;
34
			
35
			return $this->results;
36
		} else {
37
			return false;
38
		}
39
	}
40
}