Completed
Branch dev (71673f)
by
unknown
05:17
created

getFrameworkNameVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Admin Page Framework
4
 * 
5
 * http://en.michaeluno.jp/admin-page-framework/
6
 * Copyright (c) 2013-2016 Michael Uno; Licensed MIT
7
 * 
8
 */
9
10
/**
11
 * Provides utility methods which can be accessed among different components of the framework.
12
 *
13
 * @since           3.7.1
14
 * @extends         AdminPageFramework_WPUtility
15
 * @package         AdminPageFramework
16
 * @subpackage      Common/Utility
17
 * @internal
18
 */
19
class AdminPageFramework_FrameworkUtility extends AdminPageFramework_WPUtility {
20
    
21
    /**
22
     * Shows a PHP notice of a deprecation message.
23
     * @since       3.8.8
24
     * @return      void
25
     */
26
    static public function showDeprecationNotice( $sDeprecated, $sAlternative='', $sProgramName='' ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
27
        $sProgramName = $sProgramName ? $sProgramName : self::getFrameworkName();
28
        parent::showDeprecationNotice( $sDeprecated, $sAlternative, $sProgramName );
29
    }
30
    
31
    /**
32
     * Sorts admin sub-menu items.
33
     * 
34
     * @since       3.7.4
35
     * @return      void
36
     * @internal
37
     */
38
    static public function sortAdminSubMenu() {
1 ignored issue
show
Coding Style introduced by
sortAdminSubMenu uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
39
        
40
        // This method is only enough to be called only once site-wide per page load.
41
        if ( self::hasBeenCalled( __METHOD__ ) ) {
42
            return;
43
        }
44
45
        foreach( ( array ) $GLOBALS[ '_apf_sub_menus_to_sort' ] as $_sIndex => $_sMenuSlug ) {
46
            if ( ! isset( $GLOBALS[ 'submenu' ][ $_sMenuSlug ] ) ) {
47
                continue;
48
            }       
49
            ksort( $GLOBALS[ 'submenu' ][ $_sMenuSlug ] );
50
            unset( $GLOBALS[ '_apf_sub_menus_to_sort' ][ $_sIndex ] );
51
        }
52
        
53
    }    
54
    
55
    /**
56
     * Returns the used framework version.
57
     * 
58
     * This is used by field type definition classes to determine whether their required framework version is used or not.
59
     * 
60
     * <h3>Example</h3>
61
     * <code>
62
     * $oUtil    = AdminPageFramework_FrameworkUtility;
63
     * $sVersion = $oUtil->getFrameworkVersion();
64
     * </code>
65
     * 
66
     * @since       3.7.1
67
     * @since       3.7.2       Added the `$bTrimDevVer` parameter.
68
     * @param       boolean     $bTrimDevVer           Whether the `.dev` suffix should be removed or not.
69
     * @return      string
70
     */
71
    static public function getFrameworkVersion( $bTrimDevVer=false ) {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
72
        $_sVersion = AdminPageFramework_Registry::getVersion();
73
        return $bTrimDevVer
74
            ? self::getSuffixRemoved( $_sVersion, '.dev' )
75
            : $_sVersion;
76
    }
77
    
78
    /**
79
     * Return the framework name.
80
     * 
81
     * <h3>Example</h3>
82
     * <code>
83
     * $oUtil    = AdminPageFramework_FrameworkUtility;
84
     * $sVersion = $oUtil->getFrameworkName();
85
     * </code>
86
     * 
87
     * @since       3.7.1
88
     * @return      string
89
     */
90
    static public function getFrameworkName() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
91
        return AdminPageFramework_Registry::NAME;
92
    }
93
    
94
    /**
95
     * @since       3.8.5
96
     * @return      string
97
     */
98
    static public function getFrameworkNameVersion() {
1 ignored issue
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
99
        return self::getFrameworkName() . ' ' . self::getFrameworkVersion();
100
    }
101
        
102
}
103