1 | <?php |
||||
2 | |||||
3 | namespace SimplePHP\Root; |
||||
4 | |||||
5 | use Exception; |
||||
6 | use PDO; |
||||
7 | use PDOException; |
||||
8 | |||||
9 | /** |
||||
10 | * Class Connection |
||||
11 | * @package NicollasSilva\SimplePHP |
||||
12 | */ |
||||
13 | |||||
14 | abstract class Connection { |
||||
15 | |||||
16 | /** @var object|null */ |
||||
17 | protected static $conn; |
||||
18 | |||||
19 | /** @var array */ |
||||
20 | protected static $config; |
||||
21 | |||||
22 | /** |
||||
23 | * Connection construtor |
||||
24 | */ |
||||
25 | public static function getConnection() { |
||||
26 | $dotenv = \Dotenv\Dotenv::createImmutable(dirname(__DIR__, 5) . '/App/Boot/'); |
||||
0 ignored issues
–
show
|
|||||
27 | $dotenv->load(); |
||||
28 | self::$config = [ |
||||
29 | 'driver' => $_ENV['DB_CONNECTION'], |
||||
30 | 'hostname' => $_ENV['DB_HOST'], |
||||
31 | 'charset' => $_ENV['DB_CHARSET'], |
||||
32 | 'port' => $_ENV['DB_PORT'], |
||||
33 | 'database' => $_ENV['DB_DATABASE'], |
||||
34 | 'username' => $_ENV['DB_USERNAME'], |
||||
35 | 'password' => $_ENV['DB_PASSWORD'], |
||||
36 | 'timezone' => $_ENV['DB_TIMEZONE'], |
||||
37 | 'pathLog' => self::getRealDirectory() . DIRECTORY_SEPARATOR . $_ENV['PATH_LOG'] . DIRECTORY_SEPARATOR . 'Logs.log', |
||||
0 ignored issues
–
show
Are you sure
self::getRealDirectory() of type false|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
38 | 'options' => [ |
||||
39 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
||||
40 | PDO::ATTR_CASE => PDO::CASE_NATURAL, |
||||
41 | PDO::ATTR_ORACLE_NULLS => PDO::NULL_EMPTY_STRING |
||||
42 | ] |
||||
43 | ]; |
||||
44 | if(empty(self::$conn)) { |
||||
45 | self::connectPdo(); |
||||
46 | } |
||||
47 | |||||
48 | return self::$conn; |
||||
49 | } |
||||
50 | |||||
51 | /** |
||||
52 | * Function connect PDO |
||||
53 | */ |
||||
54 | public static function connectPdo() |
||||
55 | { |
||||
56 | date_default_timezone_set(self::$config['timezone']); |
||||
57 | |||||
58 | if(empty(self::$conn)) { |
||||
59 | try { |
||||
60 | self::$conn = new PDO( |
||||
61 | self::$config['driver'] . ":host=" . |
||||
62 | self::$config['hostname'] . ";charset=" . |
||||
63 | self::$config['charset'] . ";port=" . |
||||
64 | self::$config['port'] . ";dbname=" . |
||||
65 | self::$config['database'], |
||||
66 | self::$config['username'], |
||||
67 | self::$config['password'], |
||||
68 | self::$config['options'] |
||||
69 | ); |
||||
70 | } catch(PDOException $exception) { |
||||
71 | return false; |
||||
72 | } |
||||
73 | } |
||||
74 | } |
||||
75 | |||||
76 | public static function getRealDirectory() |
||||
77 | { |
||||
78 | $realDirectory = dirname(__DIR__, 5); |
||||
79 | $completeDirectoryToLog = $realDirectory . DIRECTORY_SEPARATOR . $_ENV['PATH_LOG']; |
||||
80 | |||||
81 | if(!file_exists($completeDirectoryToLog . 'Logs.log')) { |
||||
82 | try { |
||||
83 | fopen($completeDirectoryToLog . 'Logs.log', 'a'); |
||||
84 | } catch(Exception $error) { |
||||
85 | return false; |
||||
86 | } |
||||
87 | } |
||||
88 | |||||
89 | return $realDirectory; |
||||
90 | } |
||||
91 | |||||
92 | public static function find() {} |
||||
93 | } |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths