Completed
Push — add-pleio-mod ( 6d68a5 )
by
unknown
28:07
created

AccessRequests::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 8
cp 0
crap 6
1
<?php
2
namespace ModPleio;
3
4
class AccessRequests {
5
    function count() {
6
        $count = get_data_row("SELECT COUNT(*) AS total FROM pleio_request_access");
7
        return (int) $count->total;
8
    }
9
10
    function get($id) {
11
        $id = (int) $id;
12
        $entity = get_data_row("SELECT * FROM pleio_request_access WHERE id = {$id}");
13
        if ($entity) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $entity of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
14
            return new AccessRequest($entity);
15
        }
16
17
        return null;
18
    }
19
20
    function fetchAll($limit = 20, $offset = 0) {
21
        $limit = (int) $limit;
22
        $offset = (int) $offset;
23
        
24
        $return = [];
25
        $entities = get_data("SELECT * FROM pleio_request_access ORDER BY time_created DESC LIMIT {$offset}, {$limit}");
26
        foreach ($entities as $entity) {
27
            $return[] = new AccessRequest($entity);
28
        }
29
30
        return $return;
31
    }
32
}