Completed
Pull Request — master (#2)
by Beñat
02:52
created

Admin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 101
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A instance() 0 8 2
A __construct() 0 8 1
A menu() 0 13 1
A screenOptions() 0 12 1
A emailLogArchivePage() 0 22 1
1
<?php
2
3
namespace LIN3S\WPSymfonyForm\Admin;
4
5
use LIN3S\WPSymfonyForm\Admin\Storage\YamlStorage;
6
use LIN3S\WPSymfonyForm\Admin\Views\LogsTable;
7
8
/**
9
 * Main admin class.
10
 *
11
 * @author Beñat Espiña <[email protected]>
12
 */
13
final class Admin
14
{
15
    /**
16
     * The instance of the current class.
17
     *
18
     * @var self
19
     */
20
    private static $instance;
21
22
    /**
23
     * The logs table.
24
     *
25
     * @var LogsTable
26
     */
27
    public $logTable;
28
29
    /**
30
     * Singleton constructor.
31
     *
32
     * @return self
33
     */
34
    public static function instance()
35
    {
36
        if (!isset(self::$instance)) {
37
            self::$instance = new self();
38
        }
39
40
        return self::$instance;
41
    }
42
43
    /**
44
     * Constructor.
45
     */
46
    private function __construct()
47
    {
48
        add_filter('set-screen-option', function ($status, $option, $value) {
0 ignored issues
show
Unused Code introduced by
The call to the function add_filter() seems unnecessary as the function has no side-effects.
Loading history...
49
            return $value;
50
        }, 10, 3);
0 ignored issues
show
Unused Code introduced by
The call to add_filter() has too many arguments starting with 10.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
51
52
        add_action('admin_menu', [$this, 'menu']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
53
    }
54
55
    /**
56
     * Loads the menu inside WordPress admin sidebar.
57
     */
58
    public function menu()
59
    {
60
        $menu = add_menu_page(
61
            'Symfony Forms',
62
            'Symfony Forms',
63
            'manage_options',
64
            'symfony-form',
65
            [$this, 'emailLogArchivePage']
66
        );
67
68
        add_action("load-$menu", [$this, 'screenOptions']);
0 ignored issues
show
Unused Code introduced by
The call to the function add_action() seems unnecessary as the function has no side-effects.
Loading history...
69
70
    }
71
72
    /**
73
     * Adds screen options.
74
     */
75
    public function screenOptions()
76
    {
77
        add_screen_option('per_page', [
78
            'label'   => 'Logs',
79
            'default' => 10,
80
            'option'  => 'logs_per_page',
81
        ]);
82
83
        $this->logTable = new LogsTable(
84
            new YamlStorage()
85
        );
86
    }
87
88
    /**
89
     * Renders email log archive page.
90
     */
91
    public function emailLogArchivePage()
92
    {
93
        ?>
94
        <div class="wrap">
95
            <h2><?php _e('Sent emails logs', \WPSymfonyForm::TRANSLATION_DOMAIN); ?></h2>
96
            <div id="poststuff">
97
                <div id="post-body" class="metabox-holder">
98
                    <div id="post-body-content">
99
                        <div class="meta-box-sortables ui-sortable">
100
                            <form method="post">
101
                                <?php
102
                                $this->logTable->prepare_items();
103
                                $this->logTable->display(); ?>
104
                            </form>
105
                        </div>
106
                    </div>
107
                </div>
108
                <br class="clear">
109
            </div>
110
        </div>
111
        <?php
112
    }
113
}
114