Passed
Pull Request — master (#20)
by Fabrice
06:08 queued 03:04
created

ModelQueryExtractor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A setExtractQuery() 0 7 2
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\YaEtl\Extractors\DbExtractorAbstract;
14
use fab2s\YaEtl\YaEtlException;
15
use Illuminate\Database\Eloquent\Builder;
16
17
/**
18
 * Class ModelQueryExtractor
19
 */
20
class ModelQueryExtractor extends DbExtractor
21
{
22
    /**
23
     * Instantiate the ModelQueryExtractor
24
     *
25
     * @param Builder|null $extractQuery
26
     *
27
     * @throws NodalFlowException
28
     * @throws YaEtlException
29
     */
30
    public function __construct(?Builder $extractQuery = null)
31
    {
32
        if ($extractQuery !== null) {
33
            $this->setExtractQuery($extractQuery);
34
        }
35
36
        parent::__construct();
37
    }
38
39
    /**
40
     * Set the extract query
41
     *
42
     * @param Builder $extractQuery
43
     *
44
     * @throws YaEtlException
45
     *
46
     * @return static
47
     */
48
    public function setExtractQuery($extractQuery): DbExtractorAbstract
49
    {
50
        if (!($extractQuery instanceof Builder)) {
0 ignored issues
show
introduced by
$extractQuery is always a sub-type of Illuminate\Database\Eloquent\Builder.
Loading history...
51
            throw new YaEtlException('Argument 1 passed to ' . __METHOD__ . ' must be an instance of ' . Builder::class . ', ' . \gettype($extractQuery) . ' given');
52
        }
53
54
        return parent::setExtractQuery($extractQuery->toBase());
55
    }
56
}
57