Completed
Push — master ( 74be15...93fb13 )
by Wanderson
02:18
created

Database::validateConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
nc 2
cc 2
eloc 5
nop 0
1
<?php
2
3
namespace Win\Connection;
4
5
/**
6
 * Conexão com banco de dados
7
 *
8
 */
9
use PDO;
10
use Win\Mvc\Application;
11
12
abstract class Database {
13
14
	/** @var \static */
15
	static protected $instance;
16
17
	/** @var PDO */
18
	protected $pdo;
19
20
	/**
21
	 * Cria e retorna conexao PDO
22
	 * @param string[] $dbConfig
23
	 * @return PDO
24
	 */
25
	abstract function connect(&$dbConfig);
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
27
	/** @return PDO */
28
	final public function getPDO() {
29
		return $this->pdo;
30
	}
31
32
	/** @return static */
33
	final static function instance() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
34
		return self::$instance;
35
	}
36
37
	/**
38
	 * Cria uma conexão com um banco de dados
39
	 * @param string[] $dbConfig
40
	 */
41
	public function __construct($dbConfig) {
42
		self::$instance = $this;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this of type this<Win\Connection\Database> is incompatible with the declared type object<static> of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
		try {
44
			$this->pdo = $this->connect($dbConfig);
45
		} catch (\PDOException $ex) {
46
			Application::app()->errorPage(503);
47
			Application::app()->view->addData('error', $ex->getMessage());
48
		}
49
	}
50
51
}
52