DelayedExtractQueryTrait::setExtractQuery()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
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\YaEtl\Extractors\DbExtractorAbstract;
13
use fab2s\YaEtl\YaEtlException;
14
use Illuminate\Database\Query\Builder;
15
16
trait DelayedExtractQueryTrait
17
{
18
    /**
19
     * Set the extract query
20
     *
21
     * @param Builder $extractQuery
22
     *
23
     * @throws YaEtlException
24
     *
25
     * @return static
26
     */
27
    public function setExtractQuery($extractQuery): DbExtractorAbstract
28
    {
29
        if (!($extractQuery instanceof Builder)) {
0 ignored issues
show
introduced by
$extractQuery is always a sub-type of Illuminate\Database\Query\Builder.
Loading history...
30
            throw new YaEtlException('Argument 1 passed to ' . __METHOD__ . ' must be an instance of ' . Builder::class . ', ' . \gettype($extractQuery) . ' given');
31
        }
32
33
        if (!isset($this->pdo)) {
34
            $this->configurePdo($extractQuery->getConnection()->getPdo());
0 ignored issues
show
Bug introduced by
It seems like configurePdo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

34
            $this->/** @scrutinizer ignore-call */ 
35
                   configurePdo($extractQuery->getConnection()->getPdo());
Loading history...
35
        }
36
37
        parent::setExtractQuery($extractQuery);
38
39
        return $this;
40
    }
41
}
42