LogicalConnectionFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 42
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 23 4
1
<?php
2
namespace PSB\Persistence\Doctrine1;
3
4
5
use PSB\Core\Exception\UnexpectedValueException;
6
use PSB\Core\Util\Settings;
7
8
class LogicalConnectionFactory
9
{
10
    /**
11
     * @var Settings
12
     */
13
    private $settings;
14
15
    /**
16
     * @param Settings $settings
17
     */
18 6
    public function __construct(Settings $settings)
19
    {
20 6
        $this->settings = $settings;
21 6
    }
22
23
    /**
24
     * @return LogicalConnection
25
     */
26 4
    public function __invoke()
27
    {
28 4
        $logicalConnection = $this->settings->tryGet(Doctrine1KnownSettingsEnum::LOGICAL_CONNECTION);
29 4
        if ($logicalConnection) {
30 1
            return $logicalConnection;
31
        }
32
33 3
        $dsn = $this->settings->tryGet(Doctrine1KnownSettingsEnum::DSN);
34 3
        if (!$dsn) {
35 1
            throw new UnexpectedValueException(
36
                "The Doctrine 1 persistence requires a DSN. You can provide it through the persistence configurator."
37 1
            );
38
        }
39
40 2
        $manager = $this->settings->tryGet(Doctrine1KnownSettingsEnum::MANAGER);
41 2
        if (!$manager) {
42 1
            $manager = \Doctrine_Manager::getInstance();
43 1
        }
44
45 2
        $connectionName = $this->settings->tryGet(Doctrine1KnownSettingsEnum::CONNECTION_NAME);
46
47 2
        return new LogicalConnection($connectionName, $dsn, $manager);
48
    }
49
}
50