Conditions | 4 |
Paths | 2 |
Total Lines | 29 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
24 | 20 | public function __construct( \PDO $pdo, UserAbstract $user = null, $table = null ) |
|
25 | { |
||
26 | 20 | $this->table = $table ?: $this->table; |
|
27 | |||
28 | // ID is listed twice here in order to use it with FETCH_UNIQUE as array key |
||
29 | $sql = "SELECT |
||
30 | id, |
||
31 | id AS id, |
||
32 | user_first_name AS first_name, |
||
33 | user_last_name AS last_name, |
||
34 | user_login_name AS login_name, |
||
35 | user_display_name AS display_name, |
||
36 | user_email AS email, |
||
37 | api_key AS api_key, |
||
38 | is_active AS is_active, |
||
39 | created AS created, |
||
40 | updated AS updated |
||
41 | |||
42 | 20 | FROM {$this->table}"; |
|
43 | |||
44 | 20 | $stmt = $pdo->prepare( $sql ); |
|
45 | |||
46 | 20 | $stmt->setFetchMode( \PDO::FETCH_CLASS, $user ? get_class($user) : User::class ); |
|
|
|||
47 | |||
48 | 20 | if (!$stmt->execute()): |
|
49 | 10 | throw new \RuntimeException("Could not retrieve Users from database"); |
|
50 | endif; |
||
51 | |||
52 | 10 | $this->users = $stmt->fetchAll(\PDO::FETCH_UNIQUE); |
|
53 | 10 | } |
|
57 |