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

Mock::connection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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