Completed
Push — feature/pilot_information ( 13ff1e...cc067b )
by Laurent
01:46
created

PilotQueryRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A query() 0 29 4
1
<?php
2
3
4
namespace FlightLog\Infrastructure\Pilot\Query\Repository;
5
6
7
use FlightLog\Application\Pilot\ViewModel\Pilot;
8
9
final class PilotQueryRepository
10
{
11
    /**
12
     * @var \DoliDB
13
     */
14
    private $db;
15
16
    public function __construct(\DoliDB $db)
17
    {
18
        $this->db = $db;
19
    }
20
21
    /**
22
     * @return array|Pilot[]
23
     */
24
    public function query():array{
25
        $sql = sprintf('SELECT 
26
            lastname as name,
27
            firstname as firstname,
28
            email as email,
29
            rowid as id
30
        FROM llx_user
31
        WHERE  statut = 1 
32
        AND firstname != \'\' 
33
        AND employee = 1
34
        ORDER BY lastname, firstname');
35
36
        $resql = $this->db->query($sql);
37
        if (!$resql) {
38
            return [];
39
        }
40
41
        $num = $this->db->num_rows($resql);
42
        if ($num === 0) {
43
            return [];
44
        }
45
46
        $pilots = [];
47
        for($i = 0; $i < $num ; $i++) {
48
            $pilots[] = Pilot::fromArray($this->db->fetch_array($resql));
49
        }
50
51
        return $pilots;
52
    }
53
54
}