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

Result::mapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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