Passed
Push — master ( 46260f...cb5e2e )
by Jean Paul
01:23
created

DatabaseLoader::getConnector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Coco\SourceWatcher\Core\Loaders;
4
5
use Coco\SourceWatcher\Core\Database\Connections\Connector;
6
use Coco\SourceWatcher\Core\IO\Outputs\DatabaseOutput;
7
use Coco\SourceWatcher\Core\Loader;
8
use Coco\SourceWatcher\Core\Row;
9
use Coco\SourceWatcher\Core\SourceWatcherException;
10
11
class DatabaseLoader extends Loader
12
{
13
    /**
14
     * @param Row $row
15
     * @throws SourceWatcherException
16
     */
17
    public function load ( Row $row )
18
    {
19
        $this->insert( $row );
20
    }
21
22
    /**
23
     * @param Row $row
24
     * @throws SourceWatcherException
25
     */
26
    protected function insert ( Row $row ) : void
27
    {
28
        if ( $this->output == null ) {
29
            throw new SourceWatcherException( "An output must be provided." );
30
        }
31
32
        $outputIsDatabaseOutput = $this->output instanceof DatabaseOutput;
33
34
        if ( !$outputIsDatabaseOutput ) {
35
            throw new SourceWatcherException( sprintf( "The output must be an instance of %s", DatabaseOutput::class ) );
36
        }
37
38
        if ( $this->output->getOutput() == null ) {
39
            throw new SourceWatcherException( "No connector found. Set a connector before trying to insert a row." );
40
        }
41
42
        $this->output->getOutput()->insert( $row );
43
    }
44
}
45