Test Failed
Pull Request — master (#66)
by David
03:31
created

TestCountryDao   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCountriesByUserCount() 0 12 1
A getCountriesUsingUnion() 0 14 1
A getCountriesUsingSimpleQuery() 0 10 1
A getCountriesUsingDistinctQuery() 0 10 1
1
<?php
2
3
namespace TheCodingMachine\TDBM\Dao;
4
5
use Porpaginas\Result;
6
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean;
7
use TheCodingMachine\TDBM\Test\Dao\Generated\CountryBaseDao;
8
9
/**
10
 * The CountryDao class will maintain the persistence of CountryBean class into the country table.
11
 */
12
class TestCountryDao extends CountryBaseDao
13
{
14
    /**
15
     * @return CountryBean[]|Result
16
     */
17
    public function getCountriesByUserCount()
18
    {
19
        $sql = <<<SQL
20
SELECT country.*
21
FROM country
22
LEFT JOIN users ON users.country_id = country.id
23
GROUP BY country.id
24
ORDER BY COUNT(users.id) DESC
25
SQL;
26
27
        return $this->findFromRawSql($sql);
28
    }
29
30
    /**
31
     * @return CountryBean[]|Result
32
     */
33
    public function getCountriesUsingUnion()
34
    {
35
        $sql = <<<SQL
36
SELECT country.*
37
FROM country
38
WHERE country.id = 1
39
UNION
40
SELECT country.*
41
FROM country
42
WHERE country.id = 2
43
SQL;
44
45
        return $this->findFromRawSql($sql);
46
    }
47
48
    /**
49
     * @return CountryBean[]|Result
50
     */
51
    public function getCountriesUsingSimpleQuery()
52
    {
53
        $sql = <<<SQL
54
SELECT country.*
55
FROM country
56
WHERE country.id = 1
57
SQL;
58
59
        return $this->findFromRawSql($sql);
60
    }
61
62
    /**
63
     * @return CountryBean[]|Result
64
     */
65
    public function getCountriesUsingDistinctQuery()
66
    {
67
        $sql = <<<SQL
68
SELECT DISTINCT country.*
69
FROM country
70
WHERE country.id = 1
71
SQL;
72
73
        return $this->findFromRawSql($sql);
74
    }
75
}
76