66use Psr \Log \LoggerInterface ;
77use Psr \Log \NullLogger ;
88
9- class DBConfig
9+ class DBConfig implements DBConfigInterface
1010{
11- const DEFAULT_CHARSET = 'utf8 ' ;
12- const DEFAULT_CHARSET_COLLATE = 'utf8_general_ci ' ;
11+ public const DEFAULT_CHARSET = 'utf8 ' ;
12+ public const DEFAULT_CHARSET_COLLATE = 'utf8_general_ci ' ;
1313
1414 /**
1515 * @var AbstractLogger
@@ -19,7 +19,7 @@ class DBConfig
1919 /**
2020 * @var array
2121 */
22- public $ db_config ;
22+ public array $ db_config ;
2323
2424 /**
2525 * @var string
@@ -54,7 +54,7 @@ class DBConfig
5454 /**
5555 * @var bool
5656 */
57- public $ is_lazy ;
57+ public bool $ is_lazy ;
5858
5959 /**
6060 * @var string
@@ -74,52 +74,61 @@ class DBConfig
7474 /**
7575 * @var int
7676 */
77- public $ total_queries = 0 ;
77+ public int $ total_queries = 0 ;
7878
7979 /**
8080 * @var float
8181 */
8282 public $ total_time = 0 ;
8383
84+ /**
85+ *
86+ * @param array $connection_config
87+ * @param array $options
88+ * @param LoggerInterface|null $logger
89+ */
8490 public function __construct (array $ connection_config , array $ options = [], LoggerInterface $ logger = null )
8591 {
86- $ this ->logger = is_null ($ logger ) ? new NullLogger () : $ logger ;
92+ $ this ->logger = \ is_null ($ logger ) ? new NullLogger () : $ logger ;
8793
8894 if (empty ($ connection_config )) {
8995 $ this ->logger ->emergency ("[DBWrapper Error] Connection config is empty " );
9096 throw new \RuntimeException ("[DBWrapper Error] Connection config is empty " );
9197 }
9298
9399 $ this ->db_config = $ connection_config ;
94- $ this ->driver = $ this -> db_config ['driver ' ] ?? 'mysql ' ;
95- $ this ->hostname = $ this -> db_config ['hostname ' ] ?? '127.0.0.1 ' ;
96- $ this ->port = $ this -> db_config ['port ' ] ?? 3306 ;
97- $ this ->username = $ this -> db_config ['username ' ] ?? 'root ' ;
98- $ this ->password = $ this -> db_config ['password ' ];
99- $ this ->database = $ this -> db_config ['database ' ];
100+ $ this ->driver = $ connection_config ['driver ' ] ?? 'mysql ' ;
101+ $ this ->hostname = $ connection_config ['hostname ' ] ?? '127.0.0.1 ' ;
102+ $ this ->port = $ connection_config ['port ' ] ?? 3306 ;
103+ $ this ->username = $ connection_config ['username ' ] ?? 'root ' ;
104+ $ this ->password = $ connection_config ['password ' ];
105+ $ this ->database = $ connection_config ['database ' ];
100106 $ this ->is_lazy = true ;
101107
102- if (!array_key_exists ('charset ' , $ this ->db_config )) {
108+ if (!\ array_key_exists ('charset ' , $ this ->db_config )) {
103109 $ this ->charset = self ::DEFAULT_CHARSET ;
104- } elseif (!is_null ($ this ->db_config ['charset ' ])) {
110+ } elseif (!\ is_null ($ this ->db_config ['charset ' ])) {
105111 $ this ->charset = $ this ->db_config ['charset ' ];
106112 } else {
107113 $ this ->charset = null ;
108114 }
109115
110- if (!array_key_exists ('charset_collate ' , $ this ->db_config )) {
116+ if (!\ array_key_exists ('charset_collate ' , $ this ->db_config )) {
111117 $ this ->charset_collate = self ::DEFAULT_CHARSET_COLLATE ;
112- } elseif (!is_null ($ this ->db_config ['charset_collate ' ])) {
118+ } elseif (!\ is_null ($ this ->db_config ['charset_collate ' ])) {
113119 $ this ->charset_collate = $ this ->db_config ['charset_collate ' ];
114120 } else {
115121 $ this ->charset_collate = null ;
116122 }
117123
118124 // ms
119- $ this ->slow_query_threshold = (array_key_exists ('slow_query_threshold ' , $ options )) ? (float )$ options ['slow_query_threshold ' ] : 1000 ;
125+ $ this ->slow_query_threshold
126+ = \array_key_exists ('slow_query_threshold ' , $ options )
127+ ? (float )$ options ['slow_query_threshold ' ]
128+ : 1000 ;
120129
121- // $this->is_lazy = array_key_exists('lazy', $options) ? (bool)$options['lazy'] : true;
122- $ this -> is_lazy = !array_key_exists ('lazy ' , $ options ) || (bool )$ options ['lazy ' ]; // if default = false -> remove '!' from first part.
130+ $ this ->is_lazy
131+ = !\ array_key_exists ('lazy ' , $ options ) || (bool )$ options ['lazy ' ];
123132
124133 // microseconds
125134 $ this ->slow_query_threshold /= 1000 ;
0 commit comments