Passed
Pull Request — master (#249)
by Wilmer
02:57
created

ConnectionHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createSchemaCache() 0 3 1
A createARFactory() 0 3 1
A createFactory() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Support;
6
7
use Yiisoft\ActiveRecord\ActiveRecordFactory;
8
use Yiisoft\Cache\ArrayCache;
9
use Yiisoft\Db\Cache\SchemaCache;
10
use Yiisoft\Db\Connection\ConnectionInterface;
11
use Yiisoft\Di\Container;
12
use Yiisoft\Di\ContainerConfig;
13
use Yiisoft\Factory\Factory;
14
15
abstract class ConnectionHelper
16
{
17
    protected Factory $factory;
18
19
    public function createARFactory(ConnectionInterface $db): ActiveRecordFactory
20
    {
21
        return new ActiveRecordFactory($this->createFactory($db));
22
    }
23
24
    protected function createSchemaCache(): SchemaCache
25
    {
26
        return new SchemaCache(new ArrayCache());
27
    }
28
29
    private function createFactory(ConnectionInterface $db): Factory
30
    {
31
        $container = new Container(ContainerConfig::create()->withDefinitions([ConnectionInterface::class => $db]));
32
        return new Factory($container, [ConnectionInterface::class => $db]);
33
    }
34
}
35