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.
Completed
Push — master ( e13a63...8793b7 )
by
unknown
05:54
created

SecondHandProductAdmin   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 11
dl 0
loc 103
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B getEditForm() 0 15 5
A doCancel() 0 4 1
B archive() 0 30 5
B restore() 0 22 4
1
<?php
2
3
/**
4
 * @description: for the management of Product and Product Groups only
5
 *
6
 *
7
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
8
 * @package: ecommerce
9
 * @sub-package: cms
10
 **/
11
12
class SecondHandProductAdmin extends ModelAdminEcommerceBaseClass
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
    private static $menu_priority = 3.2;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_priority is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
16
    private static $url_segment = 'secondhandproducts';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
17
18
    private static $menu_title = 'Second Hand';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
20
    private static $managed_models = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $managed_models is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
21
        'SecondHandProduct',
22
        'SecondHandArchive'
23
    );
24
25
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
        "editinsitetree",
27
        "ItemEditForm",
28
        "archive" => true,
29
        "restore" => true,
30
    );
31
32
    /**
33
     * standard SS variable
34
     * @var String
35
     */
36
    private static $menu_icon = "ecommerce/images/icons/product-file.gif";
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
37
38
39
    public function getEditForm($id = null, $fields = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
40
    {
41
        foreach (GoogleAddressField::js_requirements() as $jsFile) {
42
            Requirements::javascript($jsFile);
43
        }
44
        $form = parent::getEditForm();
45
        if (singleton($this->modelClass) instanceof SiteTree) {
46
            if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) {
47
                if ($gridField instanceof GridField) {
48
                    $gridField->setConfig(GridFieldEditOriginalPageConfigSecondHandPage::create());
49
                }
50
            }
51
        }
52
        return $form;
53
    }
54
55
56
    public function doCancel($data, $form)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    {
58
        return $this->redirect(singleton('CMSMain')->Link());
59
    }
60
61
    function archive($request){
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
archive uses the super-global variable $_GET 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...
62
        if(isset($_GET['productid'])){
63
            $id = intval($_GET['productid']);
64
            if($id) {
65
                $secondHandProduct = SecondHandProduct::get()->byID($id);
66
                $internalItemID = $secondHandProduct->InternalItemID;
67
                if (is_a($secondHandProduct, Object::getCustomClass('SiteTree'))) {
68
                    $secondHandProduct->deleteFromStage('Live');
69
                    $secondHandProduct->deleteFromStage('Stage');
70
                } else {
71
                    $secondHandProduct->delete();
72
                }
73
                //after deleting the product redirect to the archived page
74
                $archivedProduct = SecondHandArchive::get()->filter(['InternalItemID' => $internalItemID])->first();
75
                if($archivedProduct){
76
                    $this->getResponse()->addHeader(
77
                        'X-Status',
78
                        rawurlencode(_t(
79
                            'CMSMain.RESTORED',
80
                            "Archived '{title}' successfully",
81
                            array('title' => $archivedProduct->Title)
0 ignored issues
show
Documentation introduced by
array('title' => $archivedProduct->Title) is of type array<string,?,{"title":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
                        ))
83
                    );
84
                    $cmsEditLink = '/admin/secondhandproducts/SecondHandArchive/EditForm/field/SecondHandArchive/item/'.$archivedProduct->ID.'/edit';
85
                    return Controller::curr()->redirect($cmsEditLink);
86
                }
87
            }
88
        }
89
        return new SS_HTTPResponse("ERROR!", 400);
90
    }
91
92
    function restore($request){
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
restore uses the super-global variable $_GET 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...
93
        if(isset($_GET['productid'])){
94
            $id = intval($_GET['productid']);
95
            if($id) {
96
                $restoredPage = Versioned::get_latest_version("SiteTree", $id);
97
                if(!$restoredPage) 	return new SS_HTTPResponse("SiteTree #$id not found", 400);
98
                $restoredPage = $restoredPage->doRestoreToStage();
99
                $restoredPage->doPublish();
100
                $this->getResponse()->addHeader(
101
                    'X-Status',
102
                    rawurlencode(_t(
103
                        'CMSMain.RESTORED',
104
                        "Restored '{title}' successfully",
105
                        array('title' => $restoredPage->Title)
0 ignored issues
show
Documentation introduced by
array('title' => $restoredPage->Title) is of type array<string,?,{"title":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
                    ))
107
                );
108
                $cmsEditLink = '/admin/secondhandproducts/SecondHandProduct/EditForm/field/SecondHandProduct/item/'.$id.'/edit';
109
                return Controller::curr()->redirect($cmsEditLink);
110
            }
111
        }
112
        return new SS_HTTPResponse("ERROR!", 400);
113
    }
114
}
115