Passed
Push — master ( b170a3...f0e277 )
by Rougin
02:16
created

Result::affected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Rougin\Windstorm\ResultInterface;
6
7
/**
8
 * Result
9
 *
10
 * @package Windstorm
11
 * @author  Rougin Gutib <[email protected]>
12
 */
13
class Result implements ResultInterface
14
{
15
    protected $data;
16
17
    protected $type = \PDO::FETCH_ASSOC;
18
19 24
    public function __construct($data)
20
    {
21 24
        $this->data = $data;
22 24
    }
23
24
    /**
25
     * Returns a number of affected rows.
26
     *
27
     * @return integer
28
     */
29 6
    public function affected()
30
    {
31 6
        return $this->data;
32
    }
33
34
    /**
35
     * Sets the fetch type for PDO.
36
     *
37
     * @param  integer $type
38
     * @return self
39
     */
40 3
    public function type($type)
41
    {
42 3
        $this->type = $type;
43
44 3
        return $this;
45
    }
46
47
    /**
48
     * Returns the first row from result.
49
     *
50
     * @return mixed
51
     */
52 9
    public function first()
53
    {
54 9
        if ($this->data instanceof \PDOStatement)
55 9
        {
56 3
            return $this->data->fetch($this->type);
57
        }
58
59 6
        return current($this->data);
60
    }
61
62
    /**
63
     * Returns all items from the result.
64
     *
65
     * @return mixed
66
     */
67 9
    public function items()
68
    {
69 9
        if ($this->data instanceof \PDOStatement)
70 9
        {
71 6
            return $this->data->fetchAll($this->type);
72
        }
73
74 3
        return $this->data;
75
    }
76
}
77