Completed
Push — master ( 6cab57...287bd7 )
by Sam
02:34
created

uninstall.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file removes all of Tabulate's database tables and WordPress options.
4
 *
5
 * @file
6
 * @package Tabulate
7
 */
8
9
if ( ! defined( 'ABSPATH' ) || ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
10
	return false;
11
}
12
13
// Make sure all Tabulate classes are accessible.
14
require __DIR__ . '/vendor/autoload.php';
15
16
// Clear Grants' option.
17
$grants = new \WordPress\Tabulate\DB\Grants();
18
$grants->delete();
19
20
// Drop the ChangeTracker's and Reports' tables.
21
global $wpdb;
22
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = 0' );
23
foreach ( \WordPress\Tabulate\DB\ChangeTracker::table_names() as $tbl ) {
0 ignored issues
show
The expression \WordPress\Tabulate\DB\C...eTracker::table_names() of type array|string is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
24
	$wpdb->query( "DROP TABLE IF EXISTS `$tbl`;" );
25
}
26
$wpdb->query( "DROP TABLE IF EXISTS `" . \WordPress\Tabulate\DB\Reports::reports_table_name() . "`;" );
27
$wpdb->query( "DROP TABLE IF EXISTS `" . \WordPress\Tabulate\DB\Reports::report_sources_table_name() . "`;" );
28
$wpdb->query( 'SET FOREIGN_KEY_CHECKS = 1' );
29