Passed
Push — master ( ca0bed...213fce )
by Tim
02:23
created

ConnectionFactory::createConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 17
rs 10
1
<?php
2
3
/**
4
 * TechDivision\Import\Dbal\Connection\ConnectionFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2021 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-dbal
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Dbal\Connection;
22
23
use TechDivision\Import\Configuration\ConfigurationInterface;
0 ignored issues
show
Bug introduced by
The type TechDivision\Import\Conf...\ConfigurationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
/**
26
 * The connection factory implementation.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2021 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-dbal
32
 * @link      http://www.techdivision.com
33
 */
34
class ConnectionFactory
35
{
36
37
    /**
38
     * Create's and return's the connection to use.
39
     *
40
     * @param \TechDivision\Import\Dbal\Configuration\ConfigurationInterface $configuration The configuration with the data to create the connection with
41
     *
42
     * @return \TechDivision\Import\Connection\PDOConnectionWrapper The initialized connection
0 ignored issues
show
Bug introduced by
The type TechDivision\Import\Conn...on\PDOConnectionWrapper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
     */
44
    public static function createConnection(ConfigurationInterface $configuration)
45
    {
46
47
        // initialize the PDO connection
48
        $dsn = $configuration->getDatabase()->getDsn();
49
        $username = $configuration->getDatabase()->getUsername();
50
        $password = $configuration->getDatabase()->getPassword();
51
        $connection = new \PDO($dsn, $username, $password);
52
        $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
53
54
        /* As of MySQL version > 5.7.4 the ONLY_FULL_GROUP_BY is activated by default. So in some */
55
        /* cases it is necessary to activate to TRADITIONAL mode to allow certain queries to run, */
56
        /* https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_only_full_group_by       */
57
        $connection->exec('SET SESSION sql_mode = traditional');
58
59
        // reurn the wrapped PDO connection
60
        return new PDOConnectionWrapper($connection);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new TechDivision\...ionWrapper($connection) returns the type TechDivision\Import\Dbal...on\PDOConnectionWrapper which is incompatible with the documented return type TechDivision\Import\Conn...on\PDOConnectionWrapper.
Loading history...
61
    }
62
}
63