22
33namespace Coderatio \SimpleBackup ;
44
5+ use Closure ;
56use RuntimeException ;
67use Coderatio \SimpleBackup \Foundation \Database ;
78use Coderatio \SimpleBackup \Foundation \Provider ;
@@ -229,7 +230,7 @@ public function importFrom($sql_file_OR_content, $config = [])
229230 set_time_limit (3000 );
230231
231232 $ error_message = '' ;
232- $ error_status = true ;
233+ $ error_status = false ;
233234
234235 try {
235236 if (!empty ($ config )) {
@@ -279,7 +280,7 @@ public function importFrom($sql_file_OR_content, $config = [])
279280 }
280281 }
281282 } catch (\Exception $ e ) {
282- $ error_status = false ;
283+ $ error_status = true ;
283284
284285 $ this ->response = [
285286 'status ' => false ,
@@ -289,7 +290,7 @@ public function importFrom($sql_file_OR_content, $config = [])
289290
290291 $ this ->response ['message ' ] = $ error_message ;
291292
292- if ($ error_status === true ) {
293+ if ($ error_status === false ) {
293294 $ this ->response ['message ' ] = 'Importing finished successfully ' ;
294295 }
295296
@@ -354,7 +355,7 @@ public function storeAfterExportTo($path_to_store, $name = null)
354355
355356 $ this ->export_name = $ export_name ;
356357
357- if (!file_exists ($ path_to_store ) && !mkdir ($ path_to_store )) {
358+ if (!file_exists ($ path_to_store ) && !mkdir ($ path_to_store ) && ! is_dir ( $ path_to_store ) ) {
358359 throw new RuntimeException (sprintf ('Directory "%s" was not created ' , $ path_to_store ));
359360 }
360361
@@ -386,12 +387,12 @@ public function getExportedName()
386387 * This is used to chain more methods.
387388 * You can pass in a function to modify any other thing.
388389 *
389- * @param null $callback
390+ * @param Closure $callback
390391 * @return $this
391392 */
392- public function then ($ callback = null )
393+ public function then (Closure $ callback = null )
393394 {
394- if ($ callback !== null && is_callable ( $ callback ) ) {
395+ if ($ callback !== null ) {
395396 $ callback ($ this );
396397 }
397398
@@ -426,26 +427,29 @@ public function setTableLimitsOn($tables = [])
426427 return $ this ;
427428 }
428429
429- /**
430- * Include only the tables mentioned in @var $tables
431- *
432- * @param array $tables
430+ /**
431+ * Include only the tables mentioned in @param array $tables
433432 * @return $this
433+ * @throws NoTablesFoundException
434+ * @var $tables
435+ *
434436 */
435437 public function includeOnly ($ tables = [])
436438 {
437439 $ this ->include_only_some_tables = true ;
438440
439- $ this ->tables_to_include = array_filter ($ tables , function ($ table ) {
440- if (in_array ($ table , $ this ->getTargetTables ())) {
441+ $ this ->tables_to_include = array_filter ($ tables , static function ($ table ) {
442+ if (in_array ($ table , $ this ->getTargetTables (), false )) {
441443 return $ table ;
442444 }
445+
446+ return null ;
443447 });
444448
445449 $ this ->tables = $ this ->tables_to_include ;
446450
447451 if (empty ($ this ->tables_to_include )) {
448- throw new NoTablesFoundException (" No tables found to export. " );
452+ throw new NoTablesFoundException (' No tables found to export. ' );
449453 }
450454
451455 $ this ->config ['include_tables ' ] = $ this ->tables_to_include ;
@@ -455,30 +459,34 @@ public function includeOnly($tables = [])
455459 }
456460
457461 /**
458- * Exclude only the tables mentioned in @var $tables
459- *
460- * @param array $tables
462+ * Exclude only the tables mentioned in @param array $tables
461463 * @return $this
464+ * @throws NoTablesFoundException
465+ * @var $tables
466+ *
462467 */
463468 public function excludeOnly ($ tables = [])
464469 {
465470 $ this ->exclude_only_some_tables = true ;
466471
467- $ this ->tables_to_exclude = array_filter ($ this ->getTargetTables (), function ($ table ) use ($ tables ) {
468- if (in_array ($ table , $ tables )) {
472+ $ this ->tables_to_exclude = array_filter ($ this ->getTargetTables (), static function ($ table ) use ($ tables ) {
473+ if (in_array ($ table , $ tables, false )) {
469474 return $ table ;
470475 }
476+
477+ return null ;
471478 });
472479
473- $ this ->tables = array_filter ($ this ->tables , function ($ table ){
474- if (!in_array ($ table , $ this ->tables_to_exclude )) {
480+ $ this ->tables = array_filter ($ this ->tables , static function ($ table ){
481+ if (!in_array ($ table , $ this ->tables_to_exclude , false )) {
475482 return $ table ;
476483 }
477484
485+ return null ;
478486 });
479487
480488 if (empty ($ this ->tables )) {
481- throw new NoTablesFoundException (" No tables found to export. " );
489+ throw new NoTablesFoundException (' No tables found to export. ' );
482490 }
483491
484492 $ this ->config ['exclude_tables ' ] = $ this ->tables_to_exclude ;
0 commit comments