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 ( 601d4c...8bbfd0 )
by Askupa
01:57
created

DynamicCSSCompiler::enqueue_style()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 Compiler 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 DynamicCSSCompiler
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...
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 compile
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
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...
44
        {
45
            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<DynamicCSSCompiler> 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
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...
47
        }
48
        
49
        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 DynamicCSSCompiler|Singleton adds the type DynamicCSSCompiler to the return on line 49 which is incompatible with the return type documented by DynamicCSSCompiler::get_instance of type Singleton.
Loading history...
50
    }
51
    
52
    /**
53
     * Initiate the compiler by hooking to wp_print_styles
54
     */
55
    public function init()
56
    {
57
        add_action( 'wp_print_styles', array( $this, 'print_compiled_style' ) );
58
    }
59
    
60
    /**
61
     * Add a style path to the pool of styles to be compiled
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_compiled_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-compiled CSS with 
91
     * variables)
92
     * @uses wp_dynamic_css_get_variable_value filter
93
     * @return string The compiled 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
}