GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3b8b00...906caa )
by Vincent
07:26 queued 27s
created

TransientHelper::deleteAll()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Undefined\Stash;
3
4
class TransientHelper
5
{
6
    /**
7
     * Delete all transients
8
     */
9
    public function deleteAll()
10
    {
11
        $transients = $this->getAll();
12
13
        foreach ($transients as $result) {
14
            $site_wide = (strpos($result->option_name, '_site_transient') !== false);
15
            $name = str_replace($site_wide ? '_site_transient_timeout_' : '_transient_timeout_', '', $result->option_name);
16
            $name = str_replace("_transient_", "", $name);
17
18
            $this->delete_transient($name, $site_wide);
19
        }
20
    }
21
22
    /**
23
     * Delete a transient by name
24
     *
25
     * @return  bool
26
     */
27
    private function delete_transient($transient = '', $site_wide = false)
28
    {
29
        if (empty($transient)) {
30
            return false;
31
        }
32
33
        if (false !== $site_wide) {
34
            return delete_site_transient($transient);
35
        } else {
36
37
            return delete_transient($transient);
38
        }
39
    }
40
41
    /**
42
     * Get all transients from database
43
     *
44
     * @return array
45
     */
46
    private function getAll($args = array())
47
    {
48
        global $wpdb;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
49
50
        $defaults = array(
51
            'offset' => 0,
52
            'number' => 30,
53
            'search' => ''
54
        );
55
56
        $args = wp_parse_args($args, $defaults);
57
        $cache_key = md5(serialize($args));
58
        $transients = wp_cache_get($cache_key);
59
60
        if (false === $transients) {
61
62
            $sql = "SELECT * FROM $wpdb->options WHERE option_name LIKE '%\_transient\_%' AND option_name NOT LIKE '%\_transient\_timeout%'";
63
64
            if (!empty($args['search'])) {
65
66
                $search = esc_sql($args['search']);
67
                $sql .= " AND option_name LIKE '%{$search}%'";
68
            }
69
70
            $offset = absint($args['offset']);
71
            $number = absint($args['number']);
72
            $sql .= " ORDER BY option_id DESC LIMIT $offset,$number;";
73
74
            $transients = $wpdb->get_results($sql);
75
76
            wp_cache_set($cache_key, $transients, '', 3600);
77
        }
78
79
        return $transients;
80
    }
81
}