Completed
Branch dev (e92412)
by
unknown
03:45
created

GetDevelopmentVersion::___getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Loads Admin Page Framework loader plugin components.
4
 *    
5
 * @package      Admin Page Framework Loader
6
 * @copyright    Copyright (c) 2015, <Michael Uno>
7
 * @author       Michael Uno
8
 * @authorurl    http://michaeluno.jp
9
 * 
10
 */
11
12
/**
13
 * Performs an action.
14
 * 
15
 * @since       3.5.2
16
 */
17
class AdminPageFrameworkLoader_Event_Action_GetDevelopmentVersion {
18
        
19
    /**
20
     * Stores the url of the text that has the development version number.
21
     */
22
    public $sVersionTextURL = 'https://raw.githubusercontent.com/michaeluno/admin-page-framework/dev/admin-page-framework-loader.php';
23
    
24
    /**
25
     * Performs the action.
26
     * 
27
     * @since       3.6.2
28
     */
29
    public function __construct( $sActionName ) {  
30
        add_action(
31
            $sActionName,
32
            array( $this, 'replyToDoAction' )
33
        );                 
34
    }
35
    
36
    /**
37
     * @callback        action      admin_page_framework_loader_action_get_development_version
38
     * @return          void
39
     */
40
    public function replyToDoAction() {
41
        AdminPageFramework_WPUtility::setTransient(
42
            AdminPageFrameworkLoader_Registry::TRANSIENT_PREFIX . 'devver',
43
            $this->___getVersion(), // data - if an error occurs, an empty string will be given
44
            604800 // for one week
45
        );        
46
    }
47
        /**
48
         * Extracts the version number from the page contents.
49
         * 
50
         * @return      string
51
         */
52
        private function ___getVersion() {
53
            
54
            $_oUtil     = new AdminPageFramework_WPUtility;
55
            $_aHeaders  = $_oUtil->getScriptData(
56
                $this->___getPageBody(),
57
                '',  /// context
58
                array( 'version' => 'Version' ) 
59
            );
60
            return $_oUtil->getElement(
61
                $_aHeaders, // subject array
62
                'version', // dimensional keys
63
                ''  // default
64
            );
65
66
        }
67
            /**
68
             * @return      string
69
             */
70
            private function ___getPageBody() {
0 ignored issues
show
Coding Style introduced by
___getPageBody 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...
71
                $_mResponse = wp_remote_get(
72
                    $this->sVersionTextURL,
73
                    array(
74
                        //  3.7  or later, it should be true
75
                        'sslverify'  => version_compare( $GLOBALS[ 'wp_version' ], '3.7', '>=' )
76
                    )
77
                );
78
                if ( is_wp_error( $_mResponse ) ) {
79
                    return '';
80
                }
81
                return wp_remote_retrieve_body( $_mResponse );
82
            }
83
    
84
}
85