Completed
Branch dev (1e869a)
by
unknown
05:31
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
     * Sorts admin sub-menu items.
23
     * 
24
     * @since       3.7.4
25
     * @return      void
26
     * @internal
27
     */
28
    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...
29
        
30
        // This method is only enough to be called only once site-wide per page load.
31
        if ( self::hasBeenCalled( __METHOD__ ) ) {
32
            return;
33
        }
34
35
        foreach( ( array ) $GLOBALS[ '_apf_sub_menus_to_sort' ] as $_sIndex => $_sMenuSlug ) {
36
            if ( ! isset( $GLOBALS[ 'submenu' ][ $_sMenuSlug ] ) ) {
37
                continue;
38
            }       
39
            ksort( $GLOBALS[ 'submenu' ][ $_sMenuSlug ] );
40
            unset( $GLOBALS[ '_apf_sub_menus_to_sort' ][ $_sIndex ] );
41
        }
42
        
43
    }    
44
    
45
    /**
46
     * Returns the used framework version.
47
     * 
48
     * This is used by field type definition classes to determine whether their required framework version is used or not.
49
     * 
50
     * <h3>Example</h3>
51
     * <code>
52
     * $oUtil    = AdminPageFramework_FrameworkUtility;
53
     * $sVersion = $oUtil->getFrameworkVersion();
54
     * </code>
55
     * 
56
     * @since       3.7.1
57
     * @since       3.7.2       Added the `$bTrimDevVer` parameter.
58
     * @param       boolean     $bTrimDevVer           Whether the `.dev` suffix should be removed or not.
59
     * @return      string
60
     */
61
    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...
62
        $_sVersion = AdminPageFramework_Registry::getVersion();
63
        return $bTrimDevVer
64
            ? self::getSuffixRemoved( $_sVersion, '.dev' )
65
            : $_sVersion;
66
    }
67
    
68
    /**
69
     * Return the framework name.
70
     * 
71
     * <h3>Example</h3>
72
     * <code>
73
     * $oUtil    = AdminPageFramework_FrameworkUtility;
74
     * $sVersion = $oUtil->getFrameworkName();
75
     * </code>
76
     * 
77
     * @since       3.7.1
78
     * @return      string
79
     */
80
    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...
81
        return AdminPageFramework_Registry::NAME;
82
    }
83
    
84
    /**
85
     * @since       3.8.5
86
     * @return      string
87
     */
88
    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...
89
        return self::getFrameworkName() . ' ' . self::getFrameworkVersion();
90
    }
91
        
92
}
93