Completed
Branch dev (aae49a)
by
unknown
19:32
created

AdminPageFramework_Factory___Script_Base::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 1
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Admin Page Framework
4
 * 
5
 * http://en.michaeluno.jp/admin-page-framework/
6
 * Copyright (c) 2013-2015 Michael Uno; Licensed MIT
7
 * 
8
 */
9
10
/**
11
 * Provides an abstract base to create an automatic script insertion class.
12
 * 
13
 * @since       3.3.0
14
 * @since       3.5.3       Extends `AdminPageFramework_WPUtility`.
15
 * @since       DEVVER      Ranamed from `AdminPageFramework_Script_Base`.
16
 * @package     AdminPageFramework
17
 * @subpackage  JavaScript
18
 * @internal
19
 * @extends     AdminPageFramework_WPUtility
20
 */
21
abstract class AdminPageFramework_Factory___Script_Base extends AdminPageFramework_WPUtility {
2 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
22
23
    /**
24
     * Stores the enqueued script class names.
25
     * 
26
     * @since       3.3.0
27
     */
28
    static public $_aEnqueued = array();
0 ignored issues
show
Coding Style introduced by
Please declare explicit visibility instead of using a prefixed underscore.
Loading history...
29
    
30
    public $oMsg;
31
    
32
    /**
33
     * Sets up hooks and properties.
34
     * 
35
     * It will enqueue the scrip in the footer.
36
     * 
37
     * @since       3.3.0
38
     */
39
    public function __construct( $oMsg=null ) {
40
        
41
        $_sClassName = get_class( $this );
42
        if ( in_array( $_sClassName, self::$_aEnqueued ) ) {
43
            return;
44
        }
45
        self::$_aEnqueued[ $_sClassName ] = $_sClassName;
46
        $this->oMsg = $oMsg ? $oMsg : AdminPageFramework_Message::getInstance();
47
        
48
        // add_action( 'customize_controls_print_footer_scripts', array( $this, '_replyToPrintScript' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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.

Loading history...
49
        $this->registerAction(
50
            'customize_controls_print_footer_scripts', 
51
            array( $this, '_replyToPrintScript' )
52
        );
53
        
54
        $this->registerAction(
55
            'admin_footer', 
56
            array( $this, '_replyToPrintScript' )       
57
        );        
58
        
59
        $this->construct();
60
        
61
        $this->registerAction( 'wp_enqueue_scripts', array( $this, 'load' ) );
62
        
63
    }
64
    
65
    /**
66
     * The user constructor.
67
     * 
68
     * Enqueue dependencies with this method.
69
     *
70
     * @remark      This should be overridden in extended classes.
71
     * @since       3.3.0
72
     * @since       DEVVER      Changed the visibility scope from protected.
73
     * @return      void
74
     */
75
    public  function construct() {}
76
    
77
    /**
78
     * @callback    wp_enqueue_script
79
     * @since       DEVVER
80
     */
81
    public function load() {}
82
    
83
    /**
84
     * Prints the script.
85
     * 
86
     * @since       3.3.0
87
     * @internal
88
     * @return      string      The generated HTML script tag.
89
     * @callback    action      admin_footer
90
     * @callback    action      customize_controls_print_footer_scripts
91
     */
92
    public function _replyToPrintScript() {
1 ignored issue
show
Coding Style introduced by
Method name "_replyToPrintScript" should not be prefixed with an underscore to indicate visibility
Loading history...
93
        $_sScript = $this->getScript( $this->oMsg );
94
        if ( ! $_sScript ) {
95
            return;
96
        }
97
        echo "<script type='text/javascript' class='" . strtolower( get_class( $this ) ) . "'>"
98
                . '/* <![CDATA[ */'
99
                . $_sScript
100
                . '/* ]]> */'
101
            . "</script>";
102
    }
103
    
104
    /**
105
     * Returns an inline JavaScript script.
106
     * 
107
     * @remark      Extended classes just override this method and return the script.
108
     * @since       3.3.0
109
     * @param       $oMsg       object      The message object.
110
     * @return      string      The inline JavaScript script.
111
     */
112
    static public function getScript( /* $oMsg */ ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
113
        $_aParams   = func_get_args() + array( null );
114
        $_oMsg      = $_aParams[ 0 ];                 
0 ignored issues
show
Unused Code introduced by
$_oMsg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
115
        return "";  
116
    }
117
118
}
0 ignored issues
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...