Completed
Branch dev (3754ad)
by
unknown
26:32 queued 06:26
created

AdminPageFramework_Form_View___ToolTip   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 97
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A get() 0 15 2
A _getTipLinkIcon() 0 13 3
A _getTipTitle() 0 8 2
A _getDescriptions() 0 11 2
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 methods to generate tool tip outputs.
12
 * 
13
 * @package     AdminPageFramework
14
 * @subpackage  Form
15
 * @since       DEVVER
16
 * @internal
17
 */
18
class AdminPageFramework_Form_View___ToolTip extends AdminPageFramework_Form_View___Section_Base {            
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...
19
  
20
    public $aArguments      = array(
21
        'attributes'    => array(), // attributes
22
        'icon'          => null,  // the icon output
23
        'title'         => null,  
24
        'content'       => null,
25
    );
26
    
27
    public $sTitleElementID;
28
    
29
    /**
30
     * Sets up properties.
31
     * @since       3.6.0
32
     * @since       DEVVER      Changed the parameter structure.
33
     */
34
    public function __construct( /* $aArguments, $sTitleElementID */ ) {
35
36
        $_aParameters = func_get_args() + array( 
37
            $this->aArguments,                 
38
            $this->sTitleElementID,
39
        );
40
41
        if ( is_string( $_aParameters[ 0 ] ) ) {
42
            $this->aArguments[ 'content' ] = $_aParameters[ 0 ];
43
        } else {
44
            $this->aArguments = $this->getAsArray( $_aParameters[ 0 ] ) + $this->aArguments;
45
        }
46
        $this->sTitleElementID = $_aParameters[ 1 ];
47
    }
48
49
    /**
50
     * Returns HTML formatted description blocks by the given description definition.
51
     * 
52
     * @return      string      The output.
53
     */
54
    public function get() {
55
        if ( ! $this->aArguments[ 'content' ] ) {
56
            return '';
57
        }
58
        $_sHref = esc_attr( "#{$this->sTitleElementID}" );
59
        return ''
60
            . "<a href='{$_sHref}' class='admin-page-framework-form-tooltip'>"
61
            . $this->_getTipLinkIcon()
62
            . "<span class='admin-page-framework-form-tooltip-content'>"
63
                . $this->_getTipTitle()
64
                . $this->_getDescriptions()
65
            . "</a>"
66
            
67
            ;
68
    }
69
        /**
70
         * @since       DEVVER
71
         * @return      string
72
         */    
73
        private function _getTipLinkIcon() {
1 ignored issue
show
Coding Style introduced by
_getTipLinkIcon 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
Method name "_getTipLinkIcon" should not be prefixed with an underscore to indicate visibility
Loading history...
74
            
75
            if ( isset( $this->aArguments[ 'icon' ] ) ) {
76
                return $this->aArguments[ 'icon' ];
77
            }
78
            
79
            if ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) {
80
                return "<span class='dashicons dashicons-editor-help'></span>";
81
            } 
82
            
83
            return '[ ? ]';
84
            
85
        }
86
        /**
87
         * @since       DEVVER
88
         * @return      string
89
         */
90
        private function _getTipTitle() {
1 ignored issue
show
Coding Style introduced by
Method name "_getTipTitle" should not be prefixed with an underscore to indicate visibility
Loading history...
91
            if ( isset( $this->aArguments[ 'title' ] ) ) {
92
                return "<span class='admin-page-framework-form-tool-tip-title'>"
93
                    . $this->aArguments[ 'title' ]
94
                    . "</span>";
95
            }
96
            return '';
97
        }
98
        /**
99
         * @since       DEVVER
100
         * @return      string
101
         */
102
        private function _getDescriptions() {         
1 ignored issue
show
Coding Style introduced by
Method name "_getDescriptions" should not be prefixed with an underscore to indicate visibility
Loading history...
103
104
            if ( isset( $this->aArguments[ 'content' ] ) ) {
105
                return  "<span class='admin-page-framework-form-tool-tip-description'>"
106
                    
107
                    . $this->aArguments[ 'content' ]
108
                    . "</span>"
109
                    ;
110
            }
111
            return '';
112
        }
113
114
}
1 ignored issue
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...