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 ( 6f1bf4...7bdf98 )
by Askupa
02:25
created

DynamicCSSCache::update_option()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 2
c 1
b 1
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * @package   WordPress Dynamic CSS
4
 * @version   1.0.5
5
 * @author    Askupa Software <[email protected]>
6
 * @link      https://github.com/askupasoftware/wp-dynamic-css
7
 * @copyright 2016 Askupa Software
8
 */
9
10
/**
11
 * Dynamic CSS Cache Handler
12
 */
13
class DynamicCSSCache
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
{
15
    /**
16
     * @var Singleton The reference to *Singleton* instance of this class
17
     */
18
    private static $instance;
19
    
20
    /**
21
     * @var array The reference to the cached compiled CSS that is stored in the database 
22
     */
23
    private static $cache;
24
    
25
    /**
26
     * Returns the *Singleton* instance of this class.
27
     *
28
     * @return Singleton The *Singleton* instance.
29
     */
30
    public static function get_instance()
31
    {
32
        if (null === static::$instance) 
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
33
        {
34
            static::$instance = new static();
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Documentation Bug introduced by
It seems like new static() of type this<DynamicCSSCache> is incompatible with the declared type object<Singleton> of property $instance.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35
            self::load_cache();
36
        }
37
        return static::$instance;
0 ignored issues
show
Bug introduced by
Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug Compatibility introduced by
The expression static::$instance; of type DynamicCSSCache|Singleton adds the type DynamicCSSCache to the return on line 37 which is incompatible with the return type documented by DynamicCSSCache::get_instance of type Singleton.
Loading history...
38
    }
39
    
40
    /**
41
     * Returns the compiled CSS for the given handle if it exists in the cache.
42
     * Returns false otherwise.
43
     * 
44
     * @param string $handle The handle of the stylesheet
45
     * @return boolean|string
46
     */
47
    public function get( $handle )
48
    {
49
        if( array_key_exists( $handle, self::$cache ) )
50
        {
51
            return self::$cache[$handle];
52
        }
53
        return false;
54
    }
55
    
56
    /**
57
     * Update the compiled CSS for the given handle.
58
     * 
59
     * @param string $handle The handle of the stylesheet
60
     * @param type $compiled_css
61
     */
62
    public function update( $handle, $compiled_css )
63
    {
64
        self::$cache[$handle] = $compiled_css;
65
        $this->update_option();
66
    }
67
    
68
    /**
69
     * Clear the compiled CSS from cache for the given handle.
70
     * 
71
     * @param string $handle The handle of the stylesheet
72
     */
73
    public function clear( $handle )
74
    {
75
        unset(self::$cache[$handle]);
76
        $this->update_option();
77
    }
78
    
79
    /**
80
     * Load the cache value from the database or create an empty array if the
81
     * cache is empty.
82
     */
83
    private static function load_cache()
84
    {
85
        self::$cache = get_option('wp-dynamic-css-cache');
86
        
87
        if( false === self::$cache )
88
        {
89
            self::$cache = array();
90
        }
91
    }
92
    
93
    /**
94
     * Update the database option with the local cache value.
95
     */
96
    private function update_option()
97
    {
98
        update_option('wp-dynamic-css-cache', self::$cache);
99
    }
100
}