Factory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 2
1
<?php
2
/**
3
 * Factory to create RunSingle object
4
 *
5
 * @author    Matthias Gisder <[email protected]>
6
 * @copyright 2014 inGenerator Ltd
7
 * @licence   BSD
8
 */
9
10
11
namespace Ingenerator\RunSingle;
12
13
use \Ingenerator\RunSingle\PdoDatabaseObject;
14
15
class Factory
16
{
17
18
    const DB_DRIVER_FACTORY_FILE = 'run_single_config.php';
19
20
    public static function create()
21
    {
22
        $driver_factory_file_path = \realpath('./').'/'.self::DB_DRIVER_FACTORY_FILE;
23
        if (! \file_exists($driver_factory_file_path)) {
24
            throw new \Exception('Please create '.$driver_factory_file_path.' (you can find a template in src/Ingenerator/RunSingle/'.self::DB_DRIVER_FACTORY_FILE.').');
25
        }
26
27
        $logger = new ConsoleLogger;
28
29
        $driver = include($driver_factory_file_path);
30
        $driver->set_logger($logger);
31
32
        $lock_holder = new HostnameLockHolder;
33
34
        $runner    = new CommandRunner;
35
        $runsingle = new RunSingle($driver, $runner, $logger, $lock_holder);
36
37
        return $runsingle;
38
    }
39
40
}
41