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 ( 8793b7...633e45 )
by
unknown
01:35
created

UpdateSecondHandProduct::unpublish()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
4
class UpdateSecondHandProduct extends Controller
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...
5
{
6
7
    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...
8
        'unpublish' => '->MyPermissionCheck',
9
        'archive' => '->MyPermissionCheck'
10
    );
11
12
13
    /**
14
     * make the page less easy to access
15
     * (but still accessible)
16
     * - code => ip address
17
     * @var string
18
     */
19
    private static $secret_codes = array();
0 ignored issues
show
Unused Code introduced by
The property $secret_codes 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...
20
21
    function init()
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...
22
    {
23
        parent::init();
24
        if(! $this->MyPermissionCheck()) {
25
            die('you do not have access');
0 ignored issues
show
Coding Style Compatibility introduced by
The method init() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
26
        }
27
    }
28
29
    function unpublish($request)
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...
30
    {
31
        $otherID = $request->param("OtherID");
32
        if(isset($otherID)) {
33
            $internalItemID = Convert::raw2sql($otherID);
34
            $secondHandProduct = SecondHandProduct::get()->filter(['internalItemID' => $internalItemID])->first();
35
            if($secondHandProduct){
36
                $secondHandProduct->deleteFromStage('Live');
37
            }
38
        }
39
    }
40
41
    function archive($request)
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...
42
    {
43
        $otherID = $request->param("OtherID");
44
        if(isset($otherID)) {
45
            $internalItemID = Convert::raw2sql($otherID);
46
            $secondHandProduct = SecondHandProduct::get()->filter(['internalItemID' => $internalItemID])->first();
47
            if (is_a($secondHandProduct, Object::getCustomClass('SiteTree'))) {
48
                $secondHandProduct->deleteFromStage('Live');
49
                $secondHandProduct->deleteFromStage('Stage');
50
            } else {
51
                $secondHandProduct->delete();
52
            }
53
        }
54
    }
55
56
    /**
57
     * @return Boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
58
     */
59 View Code Duplication
    function MyPermissionCheck()
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $codesWithIPs = $this->Config()->get('secret_codes');
62
63
        //with a code you do not have to be logged in ...
64
        if(count($codesWithIPs)) {
65
            $ip = EcommerceCountry::get_ip();
66
            $code = $this->request->param('ID');
67
            if($code) {
68
                $testIP = isset($codesWithIPs[$code]) ? $codesWithIPs[$code] : false;
69
                if($testIP) {
70
                    if($testIP === $ip || $testIP === '*') {
71
                        return true;
72
                    }
73
                }
74
            }
75
        }
76
        return Permission::check('ADMIN');
77
    }
78
}
79