Completed
Branch dev (69a0d4)
by
unknown
33:44
created

AdminPageFramework_Utility::getClassAttribute()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 20
rs 9.2
cc 4
eloc 12
nc 3
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 utility methods which do not use WordPress functions.
12
 *
13
 * @since       2.0.0
14
 * @extends     AdminPageFramework_Utility_SystemInformation
15
 * @package     AdminPageFramework
16
 * @subpackage  Utility
17
 * @internal
18
 */
19
abstract class AdminPageFramework_Utility extends AdminPageFramework_Utility_HTMLAttribute {
1 ignored issue
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...
20
       
21
    /**
22
     * Stores calls.
23
     */
24
    static private $_aCallStack = array();
25
    
26
    /**
27
     * Checks if the given id (usually a function name) has been called throughout the page load.
28
     * 
29
     * This is used to check if a function which needs to be done only once has been already called or not.
30
     * 
31
     * @since       DEVVER
32
     * @return      boolean
33
     */
34
    static public function hasBeenCalled( $sID ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
35
        if ( isset( self::$_aCallStack[ $sID ] ) ) {
36
            return true;
37
        }
38
        self::$_aCallStack[ $sID ] = true;
39
        return false;
40
    }
41
       
42
    /**
43
     * Captures the output buffer of the given function.
44
     * @since       3.6.3
45
     * @return      string      The captured output buffer.
46
     */
47
    static public function getOutputBuffer( $oCallable, array $aParameters=array() ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
48
        
49
        ob_start(); 
50
        echo call_user_func_array( $oCallable, $aParameters );
51
        $_sContent = ob_get_contents(); 
52
        ob_end_clean(); 
53
        return $_sContent;        
54
        
55
    }
56
                  
57
    /**
58
     * Generates brief object information.
59
     * 
60
     * @remark      Meant to be used for the `__toString()` method.
61
     * @since       3.6.0
62
     * @return      string
63
     */   
64
    static public function getObjectInfo( $oInstance ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
65
        
66
        $_iCount     = count( get_object_vars( $oInstance ) );
67
        $_sClassName = get_class( $oInstance );
68
        return '(object) ' . $_sClassName . ': ' . $_iCount . ' properties.';
69
        
70
    }
71
                   
72
    
73
    /**
74
     * Returns one or the other.
75
     * 
76
     * Saves one conditional statement.
77
     * 
78
     * @remark      Use this only when the performance is not critical.
79
     * @since       3.5.3
80
     * @param       boolean|integer|double|string|array|object|resource|NULL        $mValue     The value to evaluate.
81
     * @param       boolean|integer|double|string|array|object|resource|NULL        $mTrue      The value to return when the first parameter value yields true.
82
     * @param       boolean|integer|double|string|array|object|resource|NULL        $mTrue      The value to return when the first parameter value yields false.
83
     * @return      mixed
84
     */
85
    static public function getAOrB( $mValue, $mTrue=null, $mFalse=null ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
86
        return $mValue ? $mTrue : $mFalse;
87
    }    
88
    
89
}