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 ( 73d557...f5b279 )
by
unknown
01:27
created

UpdateSecondHandProduct::MyPermissionCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
        $unpublished = false;
32
        $otherID = $request->param("OtherID");
33
        if(isset($otherID)) {
34
            $internalItemID = Convert::raw2sql($otherID);
35
            $secondHandProduct = DataObject::get_one('SecondHandProduct', ['InternalItemID' => $internalItemID]);
36
            if($secondHandProduct){
37
                $unpublished = $secondHandProduct->deleteFromStage('Live');
38
            }
39
        }
40
        return json_encode($unpublished);
41
    }
42
43
    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...
44
    {
45
        $archived = false;
46
        $otherID = $request->param("OtherID");
47
        if(isset($otherID)) {
48
            $internalItemID = Convert::raw2sql($otherID);
49
            $secondHandProduct = DataObject::get_one('SecondHandProduct', ['InternalItemID' => $internalItemID]);
50
            if(!$secondHandProduct){
51
                $secondHandProduct = Versioned::get_one_by_stage('SecondHandProduct', 'Stage', ['InternalItemID' => $internalItemID]);
0 ignored issues
show
Documentation introduced by
array('InternalItemID' => $internalItemID) is of type array<string,array|strin...temID":"array|string"}>, 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...
52
            }
53
            if (is_a($secondHandProduct, Object::getCustomClass('SiteTree'))) {
54
                $archived = $secondHandProduct->deleteFromStage('Live');
0 ignored issues
show
Unused Code introduced by
$archived is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
                $archived = $secondHandProduct->deleteFromStage('Stage');
56
            } else {
57
                $archived = $secondHandProduct->delete();
58
            }
59
        }
60
        return json_encode($archived);
61
    }
62
63
    /**
64
     * @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...
65
     */
66
    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...
67
    {
68
        $codesWithIPs = $this->Config()->get('secret_codes');
69
        $code = $this->request->param('ID');
70
        return ControllerPermissionChecker::permissionCheck($codesWithIPs, $code);
71
    }
72
}
73