These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 { |
||
14 | |||
15 | /** |
||
16 | * @var DynamicCSSCache 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 DynamicCSSCache The *Singleton* instance. |
||
29 | */ |
||
30 | public static function get_instance() { |
||
31 | |||
32 | if ( null === static::$instance ) { |
||
33 | static::$instance = new static(); |
||
34 | self::load_cache(); |
||
35 | } |
||
36 | return static::$instance; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns the compiled CSS for the given handle if it exists in the cache. |
||
41 | * Returns false otherwise. |
||
42 | * |
||
43 | * @param string $handle The handle of the stylesheet |
||
44 | * @return boolean|string |
||
45 | */ |
||
46 | public function get( $handle ) { |
||
47 | |||
48 | if ( array_key_exists( $handle, self::$cache ) ) { |
||
49 | return self::$cache[ $handle ]; |
||
50 | } |
||
51 | return false; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Update the compiled CSS for the given handle. |
||
56 | * |
||
57 | * @param string $handle The handle of the stylesheet |
||
58 | * @param string $compiled_css |
||
59 | */ |
||
60 | public function update( $handle, $compiled_css, $expiration ) { |
||
61 | |||
62 | self::$cache[ $handle ] = $compiled_css; |
||
63 | $this->update_option( $expiration ); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Clear the compiled CSS from cache for the given handle. |
||
68 | * |
||
69 | * @param string $handle The handle of the stylesheet |
||
70 | */ |
||
71 | public function clear( $handle ) { |
||
72 | |||
73 | unset( self::$cache[ $handle ] ); |
||
74 | delete_transient( 'wp-dynamic-css-cache' ); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Load the cache value from the database or create an empty array if the |
||
79 | * cache is empty. |
||
80 | */ |
||
81 | private static function load_cache() { |
||
82 | |||
83 | if ( false === ( self::$cache = get_transient( 'wp-dynamic-css-cache' ) ) ) { |
||
84 | self::$cache = []; |
||
85 | } |
||
86 | // self::$cache = get_option('wp-dynamic-css-cache'); |
||
0 ignored issues
–
show
|
|||
87 | // |
||
88 | // if( false === self::$cache ) |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
89 | // { |
||
90 | // self::$cache = array(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
64% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
91 | // } |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Update the database option with the local cache value. |
||
96 | */ |
||
97 | private function update_option( $expiration ) { |
||
98 | |||
99 | // update_option('wp-dynamic-css-cache', self::$cache); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
100 | set_transient( 'wp-dynamic-css-cache', self::$cache, $expiration ); |
||
101 | } |
||
102 | } |
||
103 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.