ResultHandlers   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
eloc 26
c 2
b 1
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDBHandler() 0 15 2
A getDBGeneratorHandler() 0 16 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, array(
28
                    \PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL
29
                ));
30
                $result = $q->execute($args);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
31
                $data = $q->fetch(\PDO::FETCH_ASSOC);
32
                while ($data) {
33
                    $value = (object) $data;
34
                    $value->data = json_decode($value->data);
35
                    $value->ctime = strtotime($value->ctime);
36
                    $value->mtime = strtotime($value->mtime);
37
                    $path = $value->path;
38
                    yield $path => $value;
39
                    $data = $q->fetch(\PDO::FETCH_ASSOC);
40
                }
41
            };
42
        }
43
    }