Code Duplication    Length = 87-101 lines in 2 locations

src/LIN3S/WPSymfonyForm/Admin/Views/Components/FormsTable.php 1 location

@@ 16-116 (lines=101) @@
13
 *
14
 * @author Beñat Espiña <[email protected]>
15
 */
16
class FormsTable extends \WP_List_Table
17
{
18
    /**
19
     * The storage.
20
     *
21
     * @var Storage
22
     */
23
    private $storage;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Storage $storage The storage
29
     */
30
    public function __construct(Storage $storage)
31
    {
32
        parent::__construct([
33
            'singular' => __('Form', \WPSymfonyForm::TRANSLATION_DOMAIN),
34
            'plural'   => __('Forms', \WPSymfonyForm::TRANSLATION_DOMAIN),
35
            'ajax'     => false,
36
        ]);
37
38
        $this->storage = $storage;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function no_items()
45
    {
46
        _e('No forms register yet', \WPSymfonyForm::TRANSLATION_DOMAIN);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function column_default($item, $column_name)
53
    {
54
        switch ($column_name) {
55
            case 'name':
56
            case 'link':
57
                return $item[$column_name];
58
            default:
59
                return print_r($item, true);
60
        }
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function get_columns()
67
    {
68
        return [
69
            'name' => __('Name', \WPSymfonyForm::TRANSLATION_DOMAIN),
70
            'link' => __('Link', \WPSymfonyForm::TRANSLATION_DOMAIN),
71
        ];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function get_sortable_columns()
78
    {
79
        return [
80
            'name' => ['name', true],
81
            'link' => ['link', false],
82
        ];
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function prepare_items()
89
    {
90
        $this->_column_headers = $this->get_column_info();
91
92
        $limit = $this->get_items_per_page('forms_per_page', 10);
93
        $offset = $this->get_pagenum();
94
        $this->items = $this->storage->findAll($limit, $offset);
95
        $total = count($this->items);
96
97
        $this->set_pagination_args([
98
            'total_items' => $total,
99
            'per_page'    => $limit,
100
        ]);
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function display()
107
    {
108
        ?>
109
        <div class="meta-box-sortables ui-sortable">
110
            <form method="post">
111
                <?php parent::display(); ?>
112
            </form>
113
        </div>
114
        <?php
115
    }
116
}
117

src/LIN3S/WPSymfonyForm/Admin/Views/FormsTable.php 1 location

@@ 16-102 (lines=87) @@
13
 *
14
 * @author Beñat Espiña <[email protected]>
15
 */
16
class FormsTable extends \WP_List_Table
17
{
18
    /**
19
     * The storage.
20
     *
21
     * @var Storage
22
     */
23
    private $storage;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Storage $storage The storage
29
     */
30
    public function __construct(Storage $storage)
31
    {
32
        parent::__construct([
33
            'singular' => __('Form', \WPSymfonyForm::TRANSLATION_DOMAIN),
34
            'plural'   => __('Forms', \WPSymfonyForm::TRANSLATION_DOMAIN),
35
            'ajax'     => false,
36
        ]);
37
38
        $this->storage = $storage;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function no_items()
45
    {
46
        _e('No forms register yet', \WPSymfonyForm::TRANSLATION_DOMAIN);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function column_default($item, $column_name)
53
    {
54
        switch ($column_name) {
55
            case 'name':
56
            case 'link':
57
                return $item[$column_name];
58
            default:
59
                return print_r($item, true);
60
        }
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function get_columns()
67
    {
68
        return [
69
            'name' => __('Name', \WPSymfonyForm::TRANSLATION_DOMAIN),
70
            'link' => __('Link', \WPSymfonyForm::TRANSLATION_DOMAIN),
71
        ];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function get_sortable_columns()
78
    {
79
        return [
80
            'name' => ['name', true],
81
            'link' => ['link', false],
82
        ];
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function prepare_items()
89
    {
90
        $this->_column_headers = $this->get_column_info();
91
92
        $limit = $this->get_items_per_page('forms_per_page', 10);
93
        $offset = $this->get_pagenum();
94
        $this->items = $this->storage->findAll($limit, $offset);
95
        $total = count($this->items);
96
97
        $this->set_pagination_args([
98
            'total_items' => $total,
99
            'per_page'    => $limit,
100
        ]);
101
    }
102
}
103