Failed Conditions
Pull Request — master (#3303)
by Sergei
14:37
created

DriverMock::_constructPdoDsn()   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\Driver;
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Schema\AbstractSchemaManager;
9
use Throwable;
10
11
class DriverMock implements Driver
12
{
13
    /** @var DatabasePlatformMock */
14
    private $platformMock;
15
16
    /** @var AbstractSchemaManager */
17
    private $schemaManagerMock;
18
19
    /**
20
     * {@inheritDoc}
21
     */
22
    public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
23
    {
24
        return new DriverConnectionMock();
25
    }
26
27
    public function getDatabasePlatform()
28
    {
29
        if (! $this->platformMock) {
30
            $this->platformMock = new DatabasePlatformMock();
31
        }
32
        return $this->platformMock;
33
    }
34
35
    public function getSchemaManager(Connection $conn)
36
    {
37
        if ($this->schemaManagerMock === null) {
38
            return new SchemaManagerMock($conn);
39
        }
40
41
        return $this->schemaManagerMock;
42
    }
43
44
    public function setDatabasePlatform(AbstractPlatform $platform)
45
    {
46
        $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...
47
    }
48
49
    public function setSchemaManager(AbstractSchemaManager $sm)
50
    {
51
        $this->schemaManagerMock = $sm;
52
    }
53
54
    public function getName()
55
    {
56
        return 'mock';
57
    }
58
59
    public function getDatabase(Connection $conn)
60
    {
61
        return;
62
    }
63
64
    public function convertExceptionCode(Throwable $exception)
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

64
    public function convertExceptionCode(/** @scrutinizer ignore-unused */ Throwable $exception)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
    {
66
        return 0;
67
    }
68
}
69