digitalwand_admin_helper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 4
lcom 2
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A digitalwand_admin_helper() 0 9 1
A DoInstall() 0 16 1
A DoUninstall() 0 14 1
A InstallFiles() 0 6 1
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 9 and the first side effect is on line 5.

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
use Bitrix\Main\Localization\Loc;
4
5
Loc::loadMessages(__FILE__);
6
7
if (class_exists('digitalwand_admin_helper')) return;
8
9
class digitalwand_admin_helper extends CModule
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...
10
{
11
    var $MODULE_ID = 'digitalwand.admin_helper';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_ID.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
12
    var $MODULE_VERSION;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_VERSION.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
13
    var $MODULE_VERSION_DATE;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_VERSION_DATE.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
14
    var $MODULE_NAME;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_NAME.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
15
    var $MODULE_DESCRIPTION;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_DESCRIPTION.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
16
    var $MODULE_GROUP_RIGHTS = 'Y';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_GROUP_RIGHTS.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
17
    var $MODULE_CSS;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $MODULE_CSS.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
18
    var $PARTNER_NAME = 'DigitalWand & Notamedia';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $PARTNER_NAME.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
19
    var $PARTNER_URI = '';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $PARTNER_URI.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
20
21
    function digitalwand_admin_helper()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
22
    {
23
        include __DIR__ . '/version.php';
24
25
        $this->MODULE_VERSION = ADMIN_HELPER_VERSION;
26
        $this->MODULE_VERSION_DATE = ADMIN_HELPER_VERSION_DATE;
27
        $this->MODULE_NAME = Loc::getMessage('ADMIN_HELPER_INSTALL_NAME');
28
        $this->MODULE_DESCRIPTION = Loc::getMessage('ADMIN_HELPER_INSTALL_DESCRIPTION');
29
    }
30
31
    function DoInstall()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
    {
33
34
        $eventManager = \Bitrix\Main\EventManager::getInstance();
35
36
        RegisterModule($this->MODULE_ID);
37
        $this->InstallFiles();
38
39
        $eventManager->registerEventHandler(
40
            'main',
41
            'OnPageStart',
42
            $this->MODULE_ID,
43
            '\DigitalWand\AdminHelper\EventHandlers',
44
            'onPageStart'
45
        );
46
    }
47
48
    function DoUninstall()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
    {
50
        $eventManager = \Bitrix\Main\EventManager::getInstance();
51
52
        UnRegisterModule($this->MODULE_ID);
53
54
        $eventManager->unRegisterEventHandler(
55
            'main',
56
            'OnPageStart',
57
            $this->MODULE_ID,
58
            '\DigitalWand\AdminHelper\EventHandlers',
59
            'onPageStart'
60
        );
61
    }
62
63
    function InstallFiles()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
InstallFiles uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
64
    {
65
        CopyDirFiles(__DIR__ . '/admin', $_SERVER['DOCUMENT_ROOT'] . '/bitrix/admin');
66
67
        return true;
68
    }
69
}