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

Result::execute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
ccs 13
cts 14
cp 0.9286
rs 9.9332
c 0
b 0
f 0
cc 4
nc 4
nop 3
crap 4.0058
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