Passed
Pull Request — master (#16)
by Fabrice
04:30 queued 02:18
created

DbExtractor::setExtractQuery()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 13
rs 10
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\Laravel\Extractors;
11
12
use fab2s\NodalFlow\NodalFlowException;
13
use fab2s\NodalFlow\YaEtlException;
14
use fab2s\YaEtl\Extractors\DbExtractorAbstract;
15
use fab2s\YaEtl\Extractors\PaginatedQueryInterface;
16
use fab2s\YaEtl\Extractors\PdoExtractor;
17
use Illuminate\Database\Query\Builder;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Query\Builder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
/**
20
 * Class DbExtractor
21
 */
22
class DbExtractor extends PdoExtractor implements PaginatedQueryInterface
23
{
24
    use DelayedExtractQueryTrait;
25
26
    /**
27
     * The record collection structure
28
     *
29
     * @var iterable
30
     */
31
    protected $extracted;
32
33
    /**
34
     * The query object
35
     *
36
     * @var Builder
37
     */
38
    protected $extractQuery;
39
40
    /**
41
     * Instantiate the DbExtractor
42
     *
43
     * @param Builder|null $extractQuery
44
     *
45
     * @throws NodalFlowException
46
     * @throws YaEtlException
47
     */
48
    public function __construct(?Builder $extractQuery = null)
49
    {
50
        if ($extractQuery !== null) {
51
            $this->setExtractQuery($extractQuery);
52
        }
53
54
        // delay configuring pdo to flow start
55
        DbExtractorAbstract::__construct();
56
    }
57
58
    /**
59
     * This method sets offset and limit in the query
60
     *
61
     * @return string the paginated query with current offset and limit
62
     */
63
    public function getPaginatedQuery(): string
64
    {
65
        $extractQuery = $this->extractQuery
66
            ->offset($this->offset)
67
            ->limit($this->batchSize);
68
        $this->queryBindings = $extractQuery->getRawBindings();
69
        $this->queryBindings = $this->queryBindings['where'];
70
71
        return $extractQuery->toSql();
72
    }
73
}
74