CiiMigrateCommand::getDbConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
// Import System/Cli/Commands/MigrateCommand
3
Yii::import('system.cli.commands.MigrateCommand');
4
/**
5
 * This class is an injection container for CDbMigration which permits us to
6
 * directly access CDbMigrations from our web application without having
7
 * access to CLI or knowing before hand what our DSN is.
8
 *
9
 * Under no circumstances, should this be called directly from command line.
10
 *
11
 */
12
class CiiMigrateCommand extends MigrateCommand
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * @var array $dsn
16
     * The DSN and CDbConnectionString information from CWebApplication
17
     */
18
    public $dsn = array();
19
20
    /**
21
     * This is our overloaded getDbConnection, allowing us to tell yii what our db connection is
22
     * without it having to go through
23
     */
24
    public function getDbConnection()
25
    {
26
        $connection = new CDbConnection("mysql:host={$this->dsn['host']};dbname={$this->dsn['dbname']}", $this->dsn['username'], $this->dsn['password']);
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
27
        $connection->setActive(true);
28
        return $connection;
29
    }
30
}