WPSymfonyForm::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * Plugin Name: WP Symfony Form
5
 * Plugin URI: http://lin3s.com
6
 * Description: WordPress plugin to allow using Symfony form component with ease
7
 * Author: LIN3S
8
 * Version: 0.4.0
9
 * Author URI: http://lin3s.com/
10
 */
11
12
new WPSymfonyForm();
0 ignored issues
show
Unused Code introduced by
The call to the method WPSymfonyForm::__construct() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
13
14
/**
15
 * Plugin WPSymfonyForm entry point class.
16
 *
17
 * @author Gorka Laucirica <[email protected]>
18
 */
19
final class WPSymfonyForm
0 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...
20
{
21
    const VERSION = '0.4.0';
22
23
    /**
24
     * Construtor.
25
     */
26
    public function __construct()
27
    {
28
        add_action('init', [$this, 'loadPlugin']);
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...
29
    }
30
31
    /**
32
     * Callback that allows to load the plugin.
33
     */
34
    public function loadPlugin()
35
    {
36
        $registry = apply_filters(
37
            'wp_symfony_form_wrappers',
38
            new \LIN3S\WPSymfonyForm\Registry\FormWrapperRegistry()
39
        );
40
41
        new \LIN3S\WPSymfonyForm\Ajax\FormSubmitAjax($registry);
42
43
        wp_enqueue_script(
0 ignored issues
show
Unused Code introduced by
The call to the function wp_enqueue_script() seems unnecessary as the function has no side-effects.
Loading history...
44
            'wp-symfony-form',
45
            plugin_dir_url(__FILE__) . '/src/LIN3S/WPSymfonyForm/Resources/js/wp-symfony-form.js',
46
            ['jquery'],
47
            self::VERSION,
48
            true
49
        );
50
51
        wp_localize_script('wp-symfony-form', 'WPSymfonyFormSettings', [
52
            'ajaxUrl' => admin_url('admin-ajax.php'),
53
        ]);
54
    }
55
}
56