Test Failed
Push — master ( 0ddf40...2f9b76 )
by Auke
03:22
created

ResultHandlers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
eloc 27
c 1
b 1
f 0
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDBGeneratorHandler() 0 17 3
A getDBHandler() 0 15 2
1
<?php
2
    namespace arc\store;
3
4
    class ResultHandlers {
5
6
        public static function getDBHandler($db)
7
        {
8
            return function($query, $args) use ($db) {
9
                $q = $db->prepare('select * from nodes where '.$query);
10
                $result = $q->execute($args);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
11
                $dataset = [];
12
                while ( $data = $q->fetch(\PDO::FETCH_ASSOC) ) {
13
                    $value = (object) $data;
14
                    $value->data = json_decode($value->data);
15
                    $value->ctime = strtotime($value->ctime);
16
                    $value->mtime = strtotime($value->mtime);
17
                    $path = $value->parent.$value->name.'/';
18
                    $dataset[$path] = $value;
19
                }
20
                return $dataset;
21
            };
22
        }
23
24
        public static function getDBGeneratorHandler($db)
25
        {
26
            return function($query, $args) use ($db) {
27
                $q = $db->prepare('select * from nodes where '.$query);
28
                $result = $q->execute($args);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
29
                $data = $q->fetch(\PDO::FETCH_ASSOC);
30
                if (!$data) {
31
                    yield $data;
32
                }
33
                while ($data) {
34
                    $value = (object) $data;
35
                    $value->data = json_decode($value->data);
36
                    $value->ctime = strtotime($value->ctime);
37
                    $value->mtime = strtotime($value->mtime);
38
                    $path = $value->path;
39
                    yield $path => $value;
40
                    $data = $q->fetch(\PDO::FETCH_ASSOC);
41
                }
42
            };
43
        }
44
    }