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

General::screenOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace LIN3S\WPSymfonyForm\Admin\Views;
4
5
use LIN3S\WPSymfonyForm\Admin\Views\Components\FormsTable;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, LIN3S\WPSymfonyForm\Admin\Views\FormsTable.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
/**
8
 * General page.
9
 *
10
 * @author Beñat Espiña <[email protected]>
11
 */
12
class General implements Page
13
{
14
    /**
15
     * The forms table component.
16
     *
17
     * @var FormsTable
18
     */
19
    private $formsTable;
20
21
    /**
22
     * Constructor.
23
     *
24
     * @param FormsTable $formsTable The logs table component
25
     */
26
    public function __construct(FormsTable $formsTable)
27
    {
28
        $this->formsTable = $formsTable;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function display()
35
    {
36
        $this->formsTable->prepare_items();
37
38
        ?>
39
        <div class="wrap">
40
            <h2><?php _e('General', \WPSymfonyForm::TRANSLATION_DOMAIN); ?></h2>
41
            <div id="poststuff">
42
                <div id="post-body" class="metabox-holder">
43
                    <div id="post-body-content">
44
                        <?php $this->formsTable->display(); ?>
45
                    </div>
46
                </div>
47
                <br class="clear">
48
            </div>
49
        </div>
50
        <?php
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function screenOptions()
57
    {
58
        add_screen_option('per_page', [
59
            'label'   => 'Forms',
60
            'default' => 10,
61
            'option'  => 'forms_per_page',
62
        ]);
63
    }
64
}
65