askupasoftware /
wp-dynamic-css
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.0 |
||
| 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 Renderer Utility Class |
||
| 12 | * |
||
| 13 | * |
||
| 14 | * Dynamic CSS Syntax |
||
| 15 | * ------------------ |
||
| 16 | * <pre> |
||
| 17 | * body {color: $body_color;} |
||
| 18 | * </pre> |
||
| 19 | * In the above example, the variable $body_color is replaced by a value |
||
| 20 | * that is retrieved by the filter wp_dynamic_css_get_variable_value. The filter |
||
| 21 | * is passed the variable name without the dollar sign, which can be used with |
||
| 22 | * get_option() or get_theme_mod() etc. |
||
| 23 | */ |
||
| 24 | class DynamicCSSRenderer |
||
|
0 ignored issues
–
show
|
|||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var Singleton The reference to *Singleton* instance of this class |
||
| 28 | */ |
||
| 29 | private static $instance; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array The list of dynamic styles paths to render |
||
| 33 | */ |
||
| 34 | private $styles = array(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Returns the *Singleton* instance of this class. |
||
| 38 | * |
||
| 39 | * @return Singleton The *Singleton* instance. |
||
| 40 | */ |
||
| 41 | public static function get_instance() |
||
| 42 | { |
||
| 43 | if (null === static::$instance) |
||
|
0 ignored issues
–
show
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 class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 44 | { |
||
| 45 | static::$instance = new static(); |
||
|
0 ignored issues
–
show
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 class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
It seems like
new static() of type this<DynamicCSSRenderer> 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...
|
|||
| 46 | static::$instance->init(); |
||
|
0 ignored issues
–
show
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 class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 47 | } |
||
| 48 | |||
| 49 | return static::$instance; |
||
|
0 ignored issues
–
show
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 class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
Loading history...
|
|||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Initiate the renderer by hooking to wp_print_styles |
||
| 54 | */ |
||
| 55 | public function init() |
||
| 56 | { |
||
| 57 | add_action( 'wp_print_styles', array( $this, 'print_rendered_style' ) ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Add a style path to the pool of styles to be rendered |
||
| 62 | * |
||
| 63 | * @param type $path The absolute path to the dynamic style |
||
| 64 | */ |
||
| 65 | public function enqueue_style( $path ) |
||
| 66 | { |
||
| 67 | $this->styles[] = $path; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Parse all styles in $this->styles and print them |
||
| 72 | */ |
||
| 73 | public function print_rendered_style() |
||
| 74 | { |
||
| 75 | ob_start(); |
||
| 76 | foreach( $this->styles as $style ) |
||
| 77 | { |
||
| 78 | include $style; |
||
| 79 | echo "\n"; |
||
| 80 | } |
||
| 81 | $css = $this->parse_css( ob_get_clean() ); |
||
| 82 | include 'style.phtml'; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Parse the given CSS string by converting the variables to their |
||
| 87 | * corresponding values retrieved by applying the filter |
||
| 88 | * wp_dynamic_css_get_variable_value. |
||
| 89 | * |
||
| 90 | * @param string $css A string containing dynamic CSS (pre-rendered CSS with |
||
| 91 | * variables) |
||
| 92 | * @uses wp_dynamic_css_get_variable_value filter |
||
| 93 | * @return string The rendered CSS after converting the variables to their |
||
| 94 | * corresponding values |
||
| 95 | */ |
||
| 96 | public function parse_css( $css ) |
||
| 97 | { |
||
| 98 | return preg_replace_callback('#\$([\w]+)#', function($matches) { |
||
| 99 | return apply_filters( 'wp_dynamic_css_get_variable_value', $matches[1]); |
||
| 100 | }, $css); |
||
| 101 | } |
||
| 102 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.