Completed
Push — master ( 50ed3b...edbf7d )
by Adeniyi
8s
created

GetData::allDESC()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Ibonly\PotatoORM;
4
5
use Ibonly\PotatoORM\GetDataInterface;
6
7
class GetData implements GetDataInterface
8
{
9
    protected $value;
10
11
    public function __construct($value)
12
    {
13
        $this->value = $value;
14
    }
15
16
    /**
17
     * get all the data in the table as an array
18
     */
19
    protected function getAllData()
20
    {
21
        return $this->value;
22
    }
23
24
    protected function DESC($limit = NULL)
25
    {
26
        $value = array_reverse($this->value);
27
        if ($limit === NULL) {
28
            return $value;
29
        } else {
30
            return array_slice($value, 0, $limit);
31
        }
32
    }
33
34
    public function allDESC($limit = NULL)
35
    {
36
        return json_encode($this->DESC($limit));
37
    }
38
39
    public function all()
40
    {
41
        return json_encode($this->getAllData());
42
    }
43
44
    /**
45
     * Get the actual fetched row and return an array
46
     */
47
    public function toArray()
48
    {
49
        return current($this->value);
50
    }
51
52
    /**
53
     * Convert the fetched row to json
54
     */
55
    public function toJson()
56
    {
57
        return json_encode($this->toArray());
58
    }
59
60
    /**
61
     * Get the output of the first jsondecoded element
62
     */
63
    public function first()
64
    {
65
        return json_decode( $this->toJson() );
66
    }
67
68
    /**
69
     * Get the count of the fetch element
70
     */
71
   public function getCount()
72
   {
73
        return count($this->value);
74
   }
75
}