Passed
Pull Request — master (#372)
by Wilmer
03:25 queued 27s
created

Mock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 3 1
A cache() 0 7 2
A queryHelper() 0 3 1
A schemaCache() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Support;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Cache\ArrayCache;
9
use Yiisoft\Cache\Cache;
10
use Yiisoft\Cache\CacheInterface;
11
use Yiisoft\Db\Cache\SchemaCache;
12
use Yiisoft\Db\Connection\ConnectionInterface;
13
use Yiisoft\Db\Query\Helper\QueryHelper;
14
15
final class Mock extends TestCase
16
{
17
    private CacheInterface|null $cache = null;
18
    private SchemaCache|null $schemaCache = null;
19
20
    public function cache(): CacheInterface
21
    {
22
        if ($this->cache === null) {
23
            $this->cache = new Cache(new ArrayCache());
24
        }
25
26
        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...
27
    }
28
29
    public function connection(): ConnectionInterface
30
    {
31
        return $this->createMock(ConnectionInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...ectionInterface::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Yiisoft\Db\Connection\ConnectionInterface.
Loading history...
32
    }
33
34
    public static function queryHelper(): QueryHelper
35
    {
36
        return new QueryHelper();
37
    }
38
39
    public function schemaCache(): SchemaCache
40
    {
41
        if ($this->schemaCache === null) {
42
            $this->schemaCache = new SchemaCache($this->cache());
43
        }
44
45
        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...
46
    }
47
}
48