Failed Conditions
Pull Request — develop (#3348)
by Sergei
65:56
created

DriverMock::convertExceptionCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Doctrine\Tests\Mocks;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\DBALException;
7
use Doctrine\DBAL\Driver;
8
use Doctrine\DBAL\Driver\Connection as DriverConnection;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Schema\AbstractSchemaManager;
11
12
class DriverMock implements Driver
13
{
14
    /** @var DatabasePlatformMock */
15
    private $platformMock;
16
17
    /** @var AbstractSchemaManager */
18
    private $schemaManagerMock;
19
20
    /**
21
     * {@inheritDoc}
22
     */
23
    public function connect(array $params, ?string $username = null, ?string $password = null, array $driverOptions = []) : DriverConnection
24
    {
25
        throw new DBALException('Not implemented');
26
    }
27
28
    public function getDatabasePlatform() : AbstractPlatform
29
    {
30
        if (! $this->platformMock) {
31
            $this->platformMock = new DatabasePlatformMock();
32
        }
33
        return $this->platformMock;
34
    }
35
36
    public function getSchemaManager(Connection $conn) : AbstractSchemaManager
37
    {
38
        if ($this->schemaManagerMock === null) {
39
            return new SchemaManagerMock($conn);
40
        }
41
42
        return $this->schemaManagerMock;
43
    }
44
45
    public function setDatabasePlatform(AbstractPlatform $platform) : void
46
    {
47
        $this->platformMock = $platform;
0 ignored issues
show
Documentation Bug introduced by
$platform is of type Doctrine\DBAL\Platforms\AbstractPlatform, but the property $platformMock was declared to be of type Doctrine\Tests\Mocks\DatabasePlatformMock. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
48
    }
49
50
    public function setSchemaManager(AbstractSchemaManager $sm) : void
51
    {
52
        $this->schemaManagerMock = $sm;
53
    }
54
55
    public function getName() : string
56
    {
57
        return 'mock';
58
    }
59
60
    public function getDatabase(Connection $conn) : ?string
61
    {
62
        return '';
63
    }
64
}
65