Passed
Push — master ( e25937...5ae73b )
by Jean Paul
01:18
created

DatabaseLoader::insert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Coco\SourceWatcher\Core\Loaders;
4
5
use Coco\SourceWatcher\Core\Database\Connections\Connector;
6
use Coco\SourceWatcher\Core\Loader;
7
use Coco\SourceWatcher\Core\Row;
8
use Coco\SourceWatcher\Core\SourceWatcherException;
9
10
class DatabaseLoader extends Loader
11
{
12
    /**
13
     * @var Connector
14
     */
15
    private Connector $connector;
16
17
    /**
18
     * @param Row $row
19
     * @throws SourceWatcherException
20
     */
21
    public function load ( Row $row )
22
    {
23
        $this->insert( $row );
24
    }
25
26
    /**
27
     * @return Connector
28
     */
29
    public function getConnector () : Connector
30
    {
31
        return $this->connector;
32
    }
33
34
    /**
35
     * @param Connector $connector
36
     */
37
    public function setConnector ( Connector $connector ) : void
38
    {
39
        $this->connector = $connector;
40
    }
41
42
    /**
43
     * @param Row $row
44
     * @throws SourceWatcherException
45
     */
46
    protected function insert ( Row $row ) : void
47
    {
48
        if ( $this->connector == null ) {
49
            throw new SourceWatcherException( "No connector found. Set a connector before trying to insert a row." );
50
        }
51
52
        $this->connector->insert( $row );
53
    }
54
}
55