Completed
Push — master ( 31de30...727b9d )
by Askupa
03:14
created

SubPage   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 17.19 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 11
loc 64
rs 10
c 0
b 0
f 0
wmc 7
lcom 2
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A add_submenu_page() 11 11 1
A enqueue_scripts() 0 9 2
A render() 0 6 1
A footer_credits() 0 4 1
A default_args() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Amarkal\Settings;
4
5
class SubPage
6
{   
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
7
    private $config;
8
    
9
    private $form;
10
    
11
    public function __construct( array $args = array() ) 
12
    {
13
        $this->config = array_merge($this->default_args(), $args);
14
        $this->form = new \Amarkal\UI\Form($this->config['fields']);
15
        
16
        \add_action('admin_menu', array($this,'add_submenu_page'));
17
        \add_action('admin_enqueue_scripts', array($this,'enqueue_scripts'));
18
    }
19
    
20 View Code Duplication
    public function add_submenu_page()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        \add_submenu_page(
23
            $this->config['parent_slug'], 
24
            $this->config['title'], 
25
            $this->config['menu_title'], 
26
            $this->config['capability'],
27
            $this->config['slug'],
28
            array($this, 'render')
29
        );
30
    }
31
    
32
    public function enqueue_scripts()
33
    {
34
        // Only enqueue styles & scripts if this is a settings page
35
        if($this->config['slug'] === filter_input(INPUT_GET, 'page'))
36
        {
37
            \wp_enqueue_style('amarkal-settings');
38
            \wp_enqueue_script('amarkal-settings');
39
        }
40
    }
41
    
42
    public function render()
43
    {
44
        $this->form->update();
45
        include __DIR__.'/SubPage.phtml';
46
        \add_filter('admin_footer_text', array($this, 'footer_credits'));
47
    }
48
    
49
    /**
50
     * Renders Amarkal's credits on the page's footer.
51
     */
52
    public function footer_credits()
53
    {
54
        echo '<span id="footer-thankyou">Created with <a href="https://github.com/askupasoftware/amarkal-settings">amarkal-settings</a>, a module within the <a href="https://github.com/askupasoftware/amarkal">Amarkal Framework</a></span>';
55
    }
56
    
57
    private function default_args()
58
    {
59
        return array(
60
            'parent_slug' => '',
61
            'slug'        => '',
62
            'title'       => '',
63
            'subtitle'    => '',
64
            'menu_title'  => '',
65
            'capability'  => 'manage_options'
66
        );
67
    }
68
}