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

AccessRequests   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 0
cts 22
cp 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 4 1
A get() 0 9 2
A fetchAll() 0 12 2
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
}