Passed
Push — master ( 2de0e2...b170a3 )
by Rougin
02:10
created

Result   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 68.75%

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 36
ccs 11
cts 16
cp 0.6875
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A first() 0 8 2
A items() 0 8 2
A type() 0 5 1
A __construct() 0 3 1
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Doctrine\DBAL\Driver\PDOStatement;
6
use Rougin\Windstorm\ResultInterface;
7
8
/**
9
 * Result
10
 *
11
 * @package Windstorm
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class Result implements ResultInterface
15
{
16
    protected $data;
17
18
    protected $type = \PDO::FETCH_ASSOC;
19
20 6
    public function __construct($data)
21
    {
22 6
        $this->data = $data;
23 6
    }
24
25
    public function type($type)
26
    {
27
        $this->type = $type;
28
29
        return $this;
30
    }
31
32 3
    public function first()
33
    {
34 3
        if ($this->data instanceof PDOStatement)
35 3
        {
36
            return $this->data->fetch($this->type);
37
        }
38
39 3
        return current($this->data);
40
    }
41
42 3
    public function items()
43
    {
44 3
        if ($this->data instanceof PDOStatement)
45 3
        {
46 3
            return $this->data->fetchAll($this->type);
47
        }
48
49
        return $this->data;
50
    }
51
}
52