Passed
Branch master (7599e2)
by Sébastien
12:18 queued 06:01
created

MultiStatement   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 16
eloc 30
dl 0
loc 121
ccs 33
cts 39
cp 0.8462
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchColumn() 0 11 2
A getIterator() 0 3 1
A add() 0 3 1
A setFetchMode() 0 7 2
A __construct() 0 3 1
A closeCursor() 0 7 2
A columnCount() 0 7 2
A fetchAll() 0 9 2
A fetch() 0 16 3
1
<?php
2
3
namespace Bdf\Prime\Sharding;
4
5
use Doctrine\DBAL\Driver\ResultStatement;
6
7
/**
8
 * Array cache statement
9
 * 
10
 * @package Bdf\Prime\Query
11
 */
12
class MultiStatement implements \IteratorAggregate, ResultStatement
13
{
14
    /**
15
     * @var ResultStatement[]
16
     */
17
    protected $statements;
18
19
    /**
20
     * @var int
0 ignored issues
show
Bug introduced by
Expected "integer" but found "int" for @var tag in member variable comment
Loading history...
21
     */
22
    protected $current = 0;
23
24
    /**
25
     * @param array $statements
26
     */
27 79
    public function __construct(array $statements = [])
28
    {
29 79
        $this->statements = $statements;
30 79
    }
31
32
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $statement should have a doc-comment as per coding-style.
Loading history...
33
     * {@inheritdoc}
34
     */
35 79
    public function add(ResultStatement $statement)
36
    {
37 79
        $this->statements[] = $statement;
38 79
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 17
    public function closeCursor()
44
    {
45 17
        foreach ($this->statements as $statement) {
46 17
            $statement->closeCursor();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\Res...tatement::closeCursor() has been deprecated: Use Result::free() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
            /** @scrutinizer ignore-deprecated */ $statement->closeCursor();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
        }
48
49 17
        unset($this->statements);
50 17
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function columnCount()
56
    {
57
        if (!isset($this->statements[0])) {
58
            return 0;
59
        }
60
61
        return $this->statements[0]->columnCount();
62
    }
63
64
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $fetchMode should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $arg2 should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $arg3 should have a doc-comment as per coding-style.
Loading history...
65
     * {@inheritdoc}
66
     */
67 17
    public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
0 ignored issues
show
Coding Style introduced by
Variable "arg2" contains numbers but this is discouraged
Loading history...
Coding Style introduced by
Variable "arg3" contains numbers but this is discouraged
Loading history...
68
    {
69 17
        foreach ($this->statements as $statement) {
70 17
            $statement->setFetchMode($fetchMode, $arg2, $arg3);
0 ignored issues
show
Coding Style introduced by
Variable "arg2" contains numbers but this is discouraged
Loading history...
Coding Style introduced by
Variable "arg3" contains numbers but this is discouraged
Loading history...
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\Res...atement::setFetchMode() has been deprecated: Use one of the fetch- or iterate-related methods. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

70
            /** @scrutinizer ignore-deprecated */ $statement->setFetchMode($fetchMode, $arg2, $arg3);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
        }
72
73 17
        return true;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getIterator()
80
    {
81
        return new \ArrayIterator($this->fetchAll());
82
    }
83
84
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $fetchMode should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $cursorOrientation should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $cursorOffset should have a doc-comment as per coding-style.
Loading history...
85
     * {@inheritdoc}
86
     */
87 79
    public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
0 ignored issues
show
Coding Style introduced by
The method parameter $cursorOrientation is never used
Loading history...
Coding Style introduced by
The method parameter $cursorOffset is never used
Loading history...
88
    {
89
        // Stop the fetch if there s no statement
90 79
        if (!isset($this->statements[$this->current])) {
91 79
            return false;
92
        }
93
94 79
        $result = $this->statements[$this->current]->fetch($fetchMode);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\ResultStatement::fetch() has been deprecated: Use fetchNumeric(), fetchAssociative() or fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
        $result = /** @scrutinizer ignore-deprecated */ $this->statements[$this->current]->fetch($fetchMode);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
95
96 79
        if (!$result) {
97
            // go to the next statement
0 ignored issues
show
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
98 79
            $this->current++;
99 79
            return $this->fetch($fetchMode);
100
        }
101
102 58
        return $result;
103
    }
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $fetchMode should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $fetchArgument should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $ctorArgs should have a doc-comment as per coding-style.
Loading history...
106
     * {@inheritdoc}
107
     */
108 19
    public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
0 ignored issues
show
Coding Style introduced by
The method parameter $fetchArgument is never used
Loading history...
Coding Style introduced by
The method parameter $ctorArgs is never used
Loading history...
109
    {
110 19
        $result = [];
111
112 19
        foreach ($this->statements as $statement) {
113 19
            $result = array_merge($result, $statement->fetchAll($fetchMode));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\ResultStatement::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

113
            $result = array_merge($result, /** @scrutinizer ignore-deprecated */ $statement->fetchAll($fetchMode));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
114
        }
115
116 19
        return $result;
117
    }
118
119
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $columnIndex should have a doc-comment as per coding-style.
Loading history...
120
     * {@inheritdoc}
121
     */
122 1
    public function fetchColumn($columnIndex = 0)
123
    {
124 1
        $result = [];
125
126 1
        foreach ($this->statements as $statement) {
127 1
            $result[] = $statement->fetchColumn($columnIndex);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Driver\Res...tatement::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

127
            $result[] = /** @scrutinizer ignore-deprecated */ $statement->fetchColumn($columnIndex);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
128
        }
129
130
        //TODO change l'interface de la méthode !
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
introduced by
There must be no blank line following an inline comment
Loading history...
Coding Style introduced by
No space found before comment text; expected "// TODO change l'interface de la méthode !" but found "//TODO change l'interface de la méthode !"
Loading history...
131
132 1
        return $result;
133
    }
134
}
135