Passed
Pull Request — 2.x (#6)
by Fabrice
03:18
created

PdoExtractor::fetchRecords()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 21
rs 9.8333

1 Method

Rating   Name   Duplication   Size   Complexity  
A PdoExtractor::getPaginatedQuery() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of YaEtl
5
 *     (c) Fabrice de Stefanis / https://github.com/fab2s/YaEtl
6
 * This source file is licensed under the MIT license which you will
7
 * find in the LICENSE file or at https://opensource.org/licenses/MIT
8
 */
9
10
namespace fab2s\YaEtl\Extractors;
11
12
use fab2s\NodalFlow\NodalFlowException;
13
use fab2s\NodalFlow\YaEtlException;
14
15
/**
16
 * Class PdoExtractor
17
 */
18
class PdoExtractor extends DbExtractorAbstract
19
{
20
    use PdoExtractorTrait;
21
22
    /**
23
     * Instantiate PdoExtractor
24
     *
25
     * @param \PDO        $pdo
26
     * @param string|null $extractQuery
27
     *
28
     * @throws NodalFlowException
29
     * @throws YaEtlException
30
     */
31
    public function __construct(\PDO $pdo, ?string $extractQuery = null)
32
    {
33
        $this->configurePdo($pdo);
34
35
        parent::__construct($extractQuery);
36
    }
37
38
    /**
39
     * Leave no trace
40
     * implement here to allow easier overriding
41
     */
42
    public function __destruct()
43
    {
44
        if ($this->driverBufferedQuery) {
45
            // set driver state back to where we met
46
            $this->pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
47
        }
48
    }
49
50
    /**
51
     * This method sets offset and limit in the query
52
     * WARNING : if you set an offset without limit,
53
     * the limit will be set to  $this->maxdefaultLimit
54
     *
55
     * @return string the paginated query with current offset and limit
56
     */
57
    protected function getPaginatedQuery(): string
58
    {
59
        return $this->extractQuery . $this->getLimitOffsetBit();
60
    }
61
}
62