PropelProvider::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Database\Business\Model\Provider;
6
7
8
use Propel\Runtime\Connection\ConnectionManagerInterface;
9
use Propel\Runtime\ServiceContainer\ServiceContainerInterface;
10
11
class PropelProvider implements PropelProviderInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $config;
17
18
    /**
19
     * @var \Propel\Runtime\ServiceContainer\ServiceContainerInterface
20
     */
21
    private $serviceContainer;
22
23
    /**
24
     * @var \Propel\Runtime\Connection\ConnectionManagerInterface
25
     */
26
    private $manager;
27
28
    /**
29
     * PropelProvider constructor.
30
     *
31
     * @param array $config
32
     * @param \Propel\Runtime\ServiceContainer\ServiceContainerInterface $serviceContainer
33
     * @param \Propel\Runtime\Connection\ConnectionManagerInterface $manager
34
     */
35 1
    public function __construct(
36
        array $config,
37
        ServiceContainerInterface $serviceContainer,
38
        ConnectionManagerInterface $manager
39
    ) {
40 1
        $this->config = $config;
41 1
        $this->serviceContainer = $serviceContainer;
42 1
        $this->manager = $manager;
43 1
    }
44
45 1
    public function init(): void
46
    {
47 1
        $this->createManager();
48 1
        $this->configure();
49 1
    }
50
51 1
    private function createManager(): void
52
    {
53 1
        $this->manager->setConfiguration($this->getManagerConfig());
0 ignored issues
show
Bug introduced by
The method setConfiguration() does not exist on Propel\Runtime\Connectio...nectionManagerInterface. It seems like you code against a sub-type of Propel\Runtime\Connectio...nectionManagerInterface such as Propel\Runtime\Connection\ConnectionManagerSingle. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $this->manager->/** @scrutinizer ignore-call */ 
54
                        setConfiguration($this->getManagerConfig());
Loading history...
54 1
        $this->manager->setName('default');
55 1
    }
56
57
    /**
58
     * @return mixed
59
     */
60 1
    private function getManagerConfig()
61
    {
62 1
        $config = $this->config['propel']['database']['connections']['default'];
63 1
        $config['model_paths'] = [
64
            0 => 'src',
65
            1 => 'vendor'
66
        ];
67 1
        return $config;
68
    }
69
70 1
    private function configure(): void
71
    {
72 1
        $this->serviceContainer->checkVersion('2.0.0');
73 1
        $this->serviceContainer->checkVersion('2.0.0-dev');
74 1
        $this->serviceContainer->setAdapterClass('default', 'pgsql');
75 1
        $this->serviceContainer->setConnectionManager('default', $this->manager);
76 1
        $this->serviceContainer->setDefaultDatasource('default');
77 1
    }
78
}
79