Passed
Pull Request — master (#372)
by Wilmer
02:53
created

Connection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getQueryCache() 0 7 2
A createCache() 0 7 2
A getSchemaCache() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Support;
6
7
use Yiisoft\Cache\ArrayCache;
8
use Yiisoft\Cache\Cache;
9
use Yiisoft\Cache\CacheInterface;
10
use Yiisoft\Db\Cache\QueryCache;
11
use Yiisoft\Db\Cache\SchemaCache;
12
13
abstract class Connection
14
{
15
    private CacheInterface|null $cache = null;
16
    private QueryCache|null $queryCache = null;
17
    private SchemaCache|null $schemaCache = null;
18
19
    public function getQueryCache(): QueryCache
20
    {
21
        if ($this->queryCache === null) {
22
            $this->queryCache = new QueryCache($this->createCache());
23
        }
24
25
        return $this->queryCache;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->queryCache could return the type null which is incompatible with the type-hinted return Yiisoft\Db\Cache\QueryCache. Consider adding an additional type-check to rule them out.
Loading history...
26
    }
27
28
    public function getSchemaCache(): SchemaCache
29
    {
30
        if ($this->schemaCache === null) {
31
            $this->schemaCache = new SchemaCache($this->createCache());
32
        }
33
34
        return $this->schemaCache;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->schemaCache could return the type null which is incompatible with the type-hinted return Yiisoft\Db\Cache\SchemaCache. Consider adding an additional type-check to rule them out.
Loading history...
35
    }
36
37
    private function createCache(): CacheInterface
38
    {
39
        if ($this->cache === null) {
40
            $this->cache = new Cache(new ArrayCache());
41
        }
42
43
        return $this->cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->cache could return the type null which is incompatible with the type-hinted return Yiisoft\Cache\CacheInterface. Consider adding an additional type-check to rule them out.
Loading history...
44
    }
45
}
46