Issues (590)

DoctrineConnectionProviderAdapter.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bdf\Prime\Console\ConnectionProvider;
4
5
use Bdf\Prime\ConnectionManager;
6
use Bdf\Prime\Exception\DBALException;
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\Connection as DoctrineConnection;
9
use Doctrine\DBAL\Tools\Console\ConnectionNotFound;
10
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
11
12
/**
13
 * The prime adapter for doctrine connection provider used by doctrine in console command
14
 */
15
class DoctrineConnectionProviderAdapter implements ConnectionProvider
16
{
17
    /**
18
     * @var ConnectionManager
19
     */
20
    private $connectionManager;
21
22
    /**
23
     * @param ConnectionManager $connectionManager
24
     */
25 2
    public function __construct(ConnectionManager $connectionManager)
26
    {
27 2
        $this->connectionManager = $connectionManager;
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 2
    public function getDefaultConnection(): Connection
34
    {
35 2
        return $this->getConnection($this->connectionManager->getDefaultConnection());
0 ignored issues
show
It seems like $this->connectionManager->getDefaultConnection() can also be of type null; however, parameter $name of Bdf\Prime\Console\Connec...dapter::getConnection() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

35
        return $this->getConnection(/** @scrutinizer ignore-type */ $this->connectionManager->getDefaultConnection());
Loading history...
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 2
    public function getConnection(string $name): Connection
42
    {
43
        try {
44 2
            $connection = $this->connectionManager->getConnection($name);
45
        } catch (DBALException $exception) {
46
            throw new ConnectionNotFound("The connection '$name' is not found.", 0, $exception);
47
        }
48
49 2
        if (!$connection instanceof DoctrineConnection) {
50
            throw new ConnectionNotFound("The connection '$name' is not a doctrine connection.");
51
        }
52
53 2
        return $connection;
54
    }
55
}
56