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

DatabaseLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setConnector() 0 3 1
A insert() 0 7 2
A getConnector() 0 3 1
A load() 0 3 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