66use  PDO ;
77use  Psr \Log \LoggerInterface ;
88use  Psr \Log \NullLogger ;
9+ use  function  array_filter ;
10+ use  function  array_key_exists ;
11+ use  function  array_keys ;
12+ use  function  array_map ;
13+ use  function  call_user_func_array ;
14+ use  function  ceil ;
15+ use  function  count ;
16+ use  function  implode ;
17+ use  function  in_array ;
18+ use  function  is_array ;
19+ use  function  is_null ;
920
1021class  PDOWrapper implements  PDOWrapperInterface
1122{
1223    /** 
1324     * MySQL-коннектор. 
1425     * 
15-      * NB: Мы не объявляем тип PDO, поскольку может передаваться как PDO, так и Arris\DBWrapper 
16-      * 
1726     * @var PDO 
1827     */ 
19-     private  $ mysql_connection
28+     private  PDO   $ mysql_connection
2029
2130    /** 
2231     * PDO-коннектор к SearchD 
2332     * 
24-      * NB: Мы не объявляем тип PDO, поскольку может передаваться как PDO, так и Arris\DBWrapper 
25-      * 
2633     * @var PDO 
2734     */ 
28-     private  $ searchd_connection
35+     private  PDO   $ searchd_connection
2936
3037    /** 
3138     * Логгер 
@@ -107,7 +114,7 @@ public function setOptions(array $options = []):array
107114     * @param callable $messenger 
108115     * @return void 
109116     */ 
110-     public  function  setConsoleMessenger (callable  $ messenger
117+     public  function  setConsoleMessenger (callable  $ messenger:  void 
111118    {
112119        $ this messenger  = $ messenger
113120    }
@@ -131,22 +138,22 @@ public function rebuildAbstractIndex(string $mysql_table, string $searchd_index,
131138        $ sphinx_connection$ this searchd_connection ;
132139
133140        if  (empty ($ searchd_index
134-             throw  new   PDOWrapperException ("Requested update of undefined index " , 1 );
141+             throw  PDOWrapperException:: create ("Requested update of undefined index " ,[] , 1 );
135142        }
136143
137144        if  (empty ($ mysql_table
138-             throw  new   PDOWrapperException ('Not defined source SQL table ' , 1 );
145+             throw  PDOWrapperException:: create ('Not defined source SQL table ' , [] , 1 );
139146        }
140147
141148        // проверяем, существует ли индекс 
142149        if  (! self ::RTIndexCheckExist ($ this searchd_connection , $ searchd_index
143-             throw  new   PDOWrapperException ("Index [ {$ searchd_index] not present " , 1 );
150+             throw  PDOWrapperException:: create ("Index [ {$ searchd_index] not present " , [], 1 );
144151        }
145152
146153
147154        $ chunk_size$ this options ['chunk_length ' ];
148-         if  (0  == $ chunk_size
149-             throw  new   PDOWrapperException ("Chunk size is ZERO " );
155+         if  (0  ===  $ chunk_size
156+             throw  PDOWrapperException:: create ("Chunk size is ZERO " );
150157        }
151158
152159        // truncate 
@@ -157,23 +164,23 @@ public function rebuildAbstractIndex(string $mysql_table, string $searchd_index,
157164        $ total_updated0 ;
158165
159166        if  ($ this options ['log_before_index ' ]) {
160-             \ call_user_func_array$ this messenger , [ "<font color='yellow'>[ {$ searchd_index]</font> index :  " , false  ]);
167+             call_user_func_array ($ this messenger , [ "<font color='yellow'>[ {$ searchd_index]</font> index :  " , false  ]);
161168        }
162169
163170        if  ($ this options ['log_total_rows_found ' ]) {
164-             \ call_user_func_array$ this messenger , [
171+             call_user_func_array ($ this messenger , [
165172                "<font color='green'> {$ total_count</font> elements found for rebuild. " 
166173            ]);
167174        }
168175
169176        // iterate chunks (ASC) 
170177        // для обратной итерации (DESC) надо писать do-while цикл? 
171178
172-         for  ($ i0 ; $ i\ ceil$ total_count$ chunk_size$ i
179+         for  ($ i0 ; $ iceil ($ total_count$ chunk_size$ i
173180            $ offset$ i$ chunk_size
174181
175182            if  ($ this options ['log_before_chunk ' ]) {
176-                 \ call_user_func_array$ this messenger , [
183+                 call_user_func_array ($ this messenger , [
177184                    "Rebuilding elements from <font color='green'> {$ offset</font>, <font color='yellow'> {$ chunk_size</font> count...  " ,
178185                    false 
179186                ]);
@@ -188,7 +195,7 @@ public function rebuildAbstractIndex(string $mysql_table, string $searchd_index,
188195            // iterate inside chunk 
189196            while  ($ item$ sthfetch ()) {
190197                if  ($ this options ['log_rows_inside_chunk ' ]) {
191-                     \ call_user_func_array$ this messenger , [
198+                     call_user_func_array ($ this messenger , [
192199                        "{$ mysql_table:  {$ item'id ' ]}" 
193200                    ]);
194201                }
@@ -209,30 +216,30 @@ public function rebuildAbstractIndex(string $mysql_table, string $searchd_index,
209216            $ breakline_after_chunk$ this options ['sleep_after_chunk ' ];
210217
211218            if  ($ this options ['log_after_chunk ' ]) {
212-                 \ call_user_func_array$ this messenger , [
219+                 call_user_func_array ($ this messenger , [
213220                    "Updated RT-index <font color='yellow'> {$ searchd_index</font>. " ,
214221                    $ breakline_after_chunk
215222                ]);
216223            } else  {
217-                 \ call_user_func_array$ this messenger , [
224+                 call_user_func_array ($ this messenger , [
218225                    "<strong>Ok</strong> " ,
219226                    $ breakline_after_chunk
220227                ]);
221228            }
222229
223230            if  ($ this options ['sleep_after_chunk ' ]) {
224-                 \ call_user_func_array$ this messenger , [
231+                 call_user_func_array ($ this messenger , [
225232                    "ZZZZzzz for  {$ this options ['sleep_time ' ]} second(s)...  " ,
226233                    false 
227234                ]);
228235                sleep ($ this options ['sleep_time ' ]);
229-                 \ call_user_func_array$ this messenger , [
236+                 call_user_func_array ($ this messenger , [
230237                    "I woke up! " 
231238                ]);
232239            }
233240        } // for 
234241        if  ($ this options ['log_after_index ' ]) {
235-             \ call_user_func_array$ this messenger , [
242+             call_user_func_array ($ this messenger , [
236243                "Total updated <strong> {$ total_updated</strong> elements for <font color='yellow'> {$ searchd_index</font> RT-index. <br> " 
237244            ]);
238245        }
@@ -273,22 +280,22 @@ private static function buildReplaceQueryMVA(string $table, array $dataset, arra
273280    {
274281        $ query"REPLACE INTO  {$ table ( " ;
275282
276-         $ dataset_keys\ array_keys$ dataset
283+         $ dataset_keysarray_keys ($ dataset
277284
278-         $ query\ implode',  ' , \ array_mapfunction  ($ i
285+         $ queryimplode (',  ' , array_map (function  ($ i
279286            return  "{$ i ;
280287        }, $ dataset_keys
281288
282289        $ query" ) VALUES (  " ;
283290
284-         $ query\ implode',  ' , \ array_mapfunction  ($ iuse  ($ mva_attributes$ dataset
285-             return  \ in_array$ i$ mva_attributes"( {$ dataset$ i) "  : ": {$ i ;
291+         $ queryimplode (',  ' , array_map (function  ($ iuse  ($ mva_attributes$ dataset
292+             return  in_array ($ i$ mva_attributes"( {$ dataset$ i) "  : ": {$ i ;
286293        }, $ dataset_keys
287294
288295        $ query" )  " ;
289296
290-         $ new_dataset\ array_filter$ datasetfunction  ($ value$ keyuse  ($ mva_attributes
291-             return  !\ in_array$ key$ mva_attributes
297+         $ new_datasetarray_filter ($ datasetfunction  ($ value$ keyuse  ($ mva_attributes
298+             return  !in_array ($ key$ mva_attributes
292299        }, ARRAY_FILTER_USE_BOTH );
293300
294301        return  [
@@ -303,17 +310,17 @@ private static function buildReplaceQueryMVA(string $table, array $dataset, arra
303310     */ 
304311    private  static  function  buildReplaceQuery (string  $ tablearray  $ datasetstring 
305312    {
306-         $ dataset_keys\ array_keys$ dataset
313+         $ dataset_keysarray_keys ($ dataset
307314
308315        $ query"REPLACE INTO  {$ table ( " ;
309316
310-         $ query\ implode',  ' , \ array_mapfunction  ($ i
317+         $ queryimplode (',  ' , array_map (function  ($ i
311318            return  "{$ i ;
312319        }, $ dataset_keys
313320
314321        $ query" ) VALUES (  " ;
315322
316-         $ query\ implode',  ' , \ array_mapfunction  ($ i
323+         $ queryimplode (',  ' , array_map (function  ($ i
317324            return  ": {$ i ;
318325        }, $ dataset_keys
319326
@@ -331,15 +338,15 @@ private static function buildReplaceQuery(string $table, array $dataset):string
331338     */ 
332339    private  static  function  setOption (array  $ options$ keynull , $ default_valuenull )
333340    {
334-         if  (!\ is_array$ options
341+         if  (!is_array ($ options
335342            return  $ default_value
336343        }
337344
338-         if  (\ is_null$ key
345+         if  (is_null ($ key
339346            return  $ default_value
340347        }
341348
342-         return  \ array_key_exists$ key$ options$ options$ key$ default_value
349+         return  array_key_exists ($ key$ options$ options$ key$ default_value
343350    }
344351
345352    private  static  function  RTIndexCheckExist ($ connectionstring  $ index
@@ -350,7 +357,7 @@ private static function RTIndexCheckExist($connection, string $index)
350357
351358        $ index_definition$ connectionquery ("SHOW TABLES LIKE ' {$ index'  " )->fetchAll ();
352359
353-         return  \ count$ index_definition0 ;
360+         return  count ($ index_definition0 ;
354361    }
355362
356363    /** 
@@ -386,6 +393,6 @@ private static function sqlGetRowsCount($pdo, string $table = '', string $condit
386393
387394        return  $ pdoquery ($ queryfetchColumn () ?? 0 ;
388395    }
396+ }
389397
390- 
391- }
398+ # -eof- # 
0 commit comments