Passed
Push — master ( e2745c...f14e7e )
by Nícollas
01:10
created

Connection::PDO()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 23
rs 9.7666
cc 3
nc 3
nop 0
1
<?php
2
3
namespace SimplePHP\Root;
4
5
use PDO;
6
use PDOException;
7
8
/**
9
 * Class Connection
10
 * @package NicollasSilva\SimplePHP
11
 */
12
13
class Connection {
14
    use Config;
15
16
    /** @var PDO */
17
    protected $conn;
18
19
    /** @var PDOException */
20
    protected $exception;
21
22
    /** @var TableName */
0 ignored issues
show
Bug introduced by
The type SimplePHP\Root\TableName 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...
23
    protected $table;
24
    
25
    /**
26
     * @param ExecutePDO
27
     */
28
    function __construct() { self::PDO(); }
0 ignored issues
show
Bug Best Practice introduced by
The method SimplePHP\Root\Connection::PDO() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
    function __construct() { self::/** @scrutinizer ignore-call */ PDO(); }
Loading history...
29
30
    /**
31
     * @return PDOConnection
0 ignored issues
show
Bug introduced by
The type SimplePHP\Root\PDOConnection 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...
32
     */
33
    public function PDO() {
34
35
        if(empty($this->conn)) {
36
        
37
            try {
38
39
                $this->conn = new PDO(
40
                    $this->config['driver'] . ":host=" .
41
                    $this->config['hostname'] . ";charset=" .
42
                    $this->config['charset'] . ";port=" .
43
                    $this->config['port'] . ";dbname=" .
44
                    $this->config['database'],
45
                    $this->config['username'],
46
                    $this->config['password'],
47
                    $this->config['options']
48
                );
49
50
            } catch(PDOException $exception) {
51
52
                echo json_encode(
53
                    ['error' => 
54
                        [
55
                            'message' => $exception->getMessage()
56
                        ]
57
                    ]);
58
    
59
            }
60
61
        }
62
63
    }
64
65
}