Completed
Push — master ( 087b27...23ccd3 )
by Artem
19s queued 17s
created

FreshDoctrineEnumBundle.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * This file is part of the FreshDoctrineEnumBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\DoctrineEnumBundle;
12
13
use Doctrine\Common\Persistence\ConnectionRegistry;
14
use Fresh\DoctrineEnumBundle\Exception\InvalidArgumentException;
15
use Symfony\Component\DependencyInjection\ContainerInterface;
16
use Symfony\Component\HttpKernel\Bundle\Bundle;
17
18
/**
19
 * FreshDoctrineEnumBundle.
20
 *
21
 * @author Artem Henvald <[email protected]>
22
 */
23
class FreshDoctrineEnumBundle extends Bundle
24
{
25
    /**
26
     * {@inheritdoc}
27
     *
28
     * @throws InvalidArgumentException
29
     * @throws \Doctrine\DBAL\DBALException
30
     * @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
31
     * @throws \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
32
     */
33
    public function boot(): void
34
    {
35
        parent::boot();
36
37
        $doctrine = $this->container->get('doctrine', ContainerInterface::NULL_ON_INVALID_REFERENCE);
38
        if (!$doctrine instanceof ConnectionRegistry) {
0 ignored issues
show
The class Doctrine\Common\Persistence\ConnectionRegistry does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
39
            throw new InvalidArgumentException('Service "doctrine" is missed in container');
40
        }
41
42
        /** @var \Doctrine\DBAL\Connection $connection */
43
        foreach ($doctrine->getConnections() as $connection) {
44
            /** @var \Doctrine\DBAL\Platforms\AbstractPlatform $databasePlatform */
45
            $databasePlatform = $connection->getDatabasePlatform();
46
47
            if (!$databasePlatform->hasDoctrineTypeMappingFor('enum') || 'string' !== $databasePlatform->getDoctrineTypeMapping('enum')) {
48
                $databasePlatform->registerDoctrineTypeMapping('enum', 'string');
49
            }
50
        }
51
    }
52
}
53