Back to the article list

22 Dec 2014

Making a Symfony application bootable again with Doctrine DBAL 2.5

SensioLabsInsight uses a dynamic analysis engine to boot applications in order to find bugs and errors impossible to find by a simple static analysis. That's why, when your application is not bootable, SensioLabsInsight triggers a code quality violation and disables some analysis rules.

In normal circumstances this error is rarely seen in the analyses performed by our users, but a recent change introduced by the 2.5 version of the DBAL project is breaking lots of projects on SensioLabsInsight.

Basically, when calling the getDatabasePlatform() method in DBAL 2.5, that call needs to establish a connection in order to evaluate the appropriate database platform class if Doctrine\DBAL\Connection is not already connected.

The workaround is to explicitly configure the database server version used by Doctrine. In Symfony applications, this is as easy as declaring the server_version parameter of Doctrine DBAL in the app/config/config.yml file. The value of this parameter must be the version number of your database server. For example, if you use MySQL, execute mysql -V to get the version and configure it as follows:

# app/config.yml
doctrine:
    dbal:
        server_version: 5.6

In addition to making your application bootable again for SensioLabsInsight, this new parameter will save your application one database call/connection on production environment.

comments powered by Disqus