Completed
Pull Request — master (#6500)
by Mathew
17:49 queued 08:41
created

SingleScalarHydrator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 27
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrateAllData() 0 21 4
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Internal\Hydration;
21
22
use Doctrine\ORM\NoResultException;
23
use Doctrine\ORM\NonUniqueResultException;
24
25
/**
26
 * Hydrator that hydrates a single scalar value from the result set.
27
 *
28
 * @since  2.0
29
 * @author Roman Borschel <[email protected]>
30
 * @author Guilherme Blanco <[email protected]>
31
 */
32
class SingleScalarHydrator extends AbstractHydrator
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37 9
    protected function hydrateAllData()
38
    {
39 9
        $data    = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
40 9
        $numRows = count($data);
41
42 9
        if ($numRows === 0) {
43 2
            throw new NoResultException();
44
        }
45
46 7
        if ($numRows > 1) {
47 2
            throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().');
48
        }
49
        
50 5
        if (count($data[key($data)]) > 1) {
51 1
            throw new NonUniqueResultException('The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().');
52
        }
53
54 4
        $result = $this->gatherScalarRowData($data[key($data)]);
55
56 4
        return array_shift($result);
57
    }
58
}
59