GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ParseDbConfigTask::connect()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * ParseDbConfigTask, Получает настройки бд.
4
 *
5
 * Настройки БД берутся из файла protected/config/db.php. Устанавливаются свойства db.driver, db.host, db.username, db.pass и db.prefix
6
 * @author Fedor A Borshev <[email protected]>
7
 * @link https://github.com/shogodev/argilla/
8
 * @copyright Copyright &copy; 2003-2014 Shogo
9
 * @license http://argilla.ru/LICENSE
10
 * @package build.tasks.ParseDbConfigTask
11
 *
12
 */
13
require_once "phing/Task.php";
14
15
class ParseDbConfigTask extends Task 
16
{
17
  private $file;
18
19
  private $pdo;
20
21
  private $connected = false;
22
23
  public function setFile($file)
24
  {
25
    $this->file = $file;
26
  }
27
28
  public function main()
29
  {
30
    if (!file_exists($this->file))
31
    {
32
      throw new BuildException('Cannot open db config file');
33
    }
34
	
35
    $db = require ($this->file);
36
37
    $this->project->setProperty('db.username',  $db['username']);
38
    $this->project->setProperty('db.password',  $db['password']);
39
    $this->project->setProperty('db.prefix',    $db['tablePrefix']);
40
41
    $connectionString = preg_replace('/\s*/', '', $db['connectionString']);
42
43
    $dbType = 'mysql';
0 ignored issues
show
Unused Code introduced by
$dbType is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
    preg_match('/^([^\:]+):/', $connectionString, $q);
45
    $dbType = $q[1];
46
					
47
    $this->project->setProperty('db.driver', $dbType);
48
49
    $dsnVars = preg_split('/:|;/', preg_replace("/^$dbType:/",'',$connectionString)); // получаем список всех свойств драйвера из $dsn в виде key = value
50
					
51
    foreach($dsnVars as $dsnVar) // переносим все свойства в проект, устанавливаем db.<свойство>
52
    {
53
      list($key, $value) = preg_split('/=/', $dsnVar);
54
      $this->project->setProperty('db.' . $key, $value);
55
    }
56
57
    $this->connect();
58
    $this->getMysqlUserHost();
59
  }
60
61
  private function getMysqlUserHost()
62
  {
63
    $q = $this->pdo->query('SELECT CURRENT_USER();');
64
    $q->execute();
65
66
    $row = $q->fetch();
67
68
    list($user, $host) = explode('@', $row[0]);
69
70
    $this->project->setProperty('db.mysqlUser', $user);
71
    $this->project->setProperty('db.mysqlHost', $host);
72
  }
73
74
  private function connect()
75
  {
76
    $dsn = $this->project->getProperty('db.driver') . ':' . 'host=' . $this->project->getProperty('db.host');
77
    try
78
    {
79
      $this->pdo = new PDO($dsn,
80
        $this->project->getProperty('db.username'),
81
        $this->project->getProperty('db.password')
82
      );
83
    } catch (PDOException $e) {
84
      throw new BuildException("ParseDbConfigTask: Could not connect to PDO: $dsn");
85
    }
86
    $this->connected = true;
87
  }
88
}
89
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
90