PdoAllUsers   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 49
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 29 4
1
<?php
2
namespace Germania\Users;
3
4
class PdoAllUsers extends Users implements UsersInterface
5
{
6
7
    /**
8
     * @var string
9
     */
10
    public $table = 'users';
11
12
13
    /**
14
     * @var array
15
     */
16
    public $users = array();
17
18
19
    /**
20
     * @param PDO           $pdo
21
     * @param UserAbstract  $user   Optional: User template object
22
     * @param string        $table  Optional: Users table name
23
     */
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 );
0 ignored issues
show
Bug introduced by
$user ? get_class($user)...mania\Users\User::class of type string is incompatible with the type integer expected by parameter $columnNumber of PDOStatement::setFetchMode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $stmt->setFetchMode( \PDO::FETCH_CLASS, /** @scrutinizer ignore-type */ $user ? get_class($user) : User::class );
Loading history...
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
    }
54
55
}
56
57