Issues (291)

tests/Dao/TestCountryDao.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TheCodingMachine\TDBM\Dao;
6
7
use TheCodingMachine\TDBM\ResultInterface;
8
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean;
0 ignored issues
show
The type TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use TheCodingMachine\TDBM\Test\Dao\Generated\CountryBaseDao;
0 ignored issues
show
The type TheCodingMachine\TDBM\Te...enerated\CountryBaseDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
/**
12
 * The CountryDao class will maintain the persistence of CountryBean class into the country table.
13
 */
14
class TestCountryDao extends CountryBaseDao
15
{
16
    /**
17
     * @return CountryBean[]|ResultInterface
18
     */
19
    public function getCountriesByUserCount()
20
    {
21
        $sql = <<<SQL
22
SELECT country.*
23
FROM country
24
LEFT JOIN users ON users.country_id = country.id
25
GROUP BY country.id, country.label
26
ORDER BY COUNT(users.id) DESC
27
SQL;
28
29
        return $this->findFromRawSql($sql);
30
    }
31
32
    /**
33
     * @return CountryBean[]|ResultInterface
34
     */
35
    public function getCountriesUsingUnion()
36
    {
37
        $sql = <<<SQL
38
SELECT country.*
39
FROM country
40
WHERE country.id = 1
41
UNION
42
SELECT country.*
43
FROM country
44
WHERE country.id = 2
45
SQL;
46
47
        return $this->findFromRawSql($sql);
48
    }
49
50
    /**
51
     * @return CountryBean[]|ResultInterface
52
     */
53
    public function getCountriesUsingSimpleQuery()
54
    {
55
        $sql = <<<SQL
56
SELECT country.*
57
FROM country
58
WHERE country.id = 1
59
SQL;
60
61
        return $this->findFromRawSql($sql);
62
    }
63
64
    /**
65
     * @return CountryBean[]|ResultInterface
66
     */
67
    public function getCountriesUsingDistinctQuery()
68
    {
69
        // Note: there are many users whose country is ID 2 (UK).
70
        // But the distinct should return only one country (including the count() call)
71
        $sql = <<<SQL
72
SELECT DISTINCT country.*
73
FROM country
74
LEFT JOIN users ON users.country_id = country.id 
75
WHERE country_id=2
76
SQL;
77
78
        return $this->findFromRawSql($sql);
79
    }
80
}
81