GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

EcommerceTaskCreateSecondHandProductManager::run()   B
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 25
nc 8
nop 1
1
<?php
2
3
4
/**
5
 * create the e-commerce specific Member Groups.
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: tasks
10
 * @inspiration: Silverstripe Ltd, Jeremy
11
 **/
12
class EcommerceTaskCreateSecondHandProductManager extends BuildTask
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...
13
{
14
    protected $title = 'Create e-commerce Second Hand Product Manager';
15
16
    protected $description = 'Create the member groups and members for second hard products';
17
18
    public function run($request)
0 ignored issues
show
Coding Style introduced by
run 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...
19
    {
20
        $permissionProviderFactory = Injector::inst()->get('PermissionProviderFactory');
21
        db::alteration_message('========================== <br />creating second hand products sales manager', 'created');
22
        $email = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_user_email');
23
        if (! $email) {
24
            $email = 'secondhandproducts@'.$_SERVER['HTTP_HOST'];
25
        }
26
        $firstName = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_user_first_name');
27
        if (!$firstName) {
28
            $firstName = 'Second Hand';
29
        }
30
        $surname = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_user_surname');
31
        if (!$surname) {
32
            $surname = 'Sales';
33
        }
34
35
        $member = $permissionProviderFactory->CreateDefaultMember(
36
            $email,
37
            $firstName,
38
            $surname
39
        );
40
        db::alteration_message('================================<br />creating shop admin group ', 'created');
41
42
        $permissionProviderFactory->CreateGroup(
43
            $code = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_group_code'),
44
            $name = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_group_name'),
45
            $parentGroup = null,
46
            $permissionCode = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_permission_code'),
47
            $roleTitle = EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_role_title'),
48
            $otherPermissionCodes = array(),
49
            $member
50
        );
51
    }
52
}
53