Completed
Pull Request — master (#20)
by Adeniyi
02:50
created

GetData   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 1
cbo 0
dl 0
loc 54
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAllData() 0 4 1
A all() 0 4 1
A toArray() 0 4 1
A toJson() 0 4 1
A first() 0 4 1
A getCount() 0 4 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
    function __construct($value)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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
    public function all()
25
    {
26
        return json_decode( json_encode( $this->getAllData() ) );
27
    }
28
29
    /**
30
     * Get the actual fetched row and return an array
31
     */
32
    protected function toArray()
33
    {
34
        return current($this->value);
35
    }
36
37
    /**
38
     * Convert the fetched row to json
39
     */
40
    protected function toJson()
41
    {
42
        return json_encode($this->toArray());
43
    }
44
45
    /**
46
     * Get the output of the first jsondecoded element
47
     */
48
    public function first()
49
    {
50
        return json_decode( $this->toJson() );
51
    }
52
53
    /**
54
     * Get the count of the fetch element
55
     */
56
   public function getCount()
57
   {
58
        return sizeof($this->value);
59
   }
60
}