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.
Passed
Push — master ( 354c7c...907f89 )
by Jamie
05:42
created

JsonPatch::handleArray()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
rs 8.8571
ccs 13
cts 13
cp 1
cc 5
eloc 9
nc 3
nop 3
crap 5
1
<?php
2
3
namespace OpenStack\Images\v2;
4
5
class JsonPatch extends \OpenStack\Common\JsonSchema\JsonPatch
6
{
7 1
    public function disableRestrictedPropRemovals(array $diff, array $restrictedProps)
8
    {
9 1
        foreach ($diff as $i => $changeSet) {
10 1
            if ($changeSet['op'] == 'remove' && in_array($changeSet['path'], $restrictedProps)) {
11 1
                unset($diff[$i]);
12 1
            }
13 1
        }
14
15 1
        return $diff;
16
    }
17
18
    /**
19
     * {@inheritDoc}
20
     *
21
     * We need to override the proper way to handle objects because Glance v2 does not
22
     * support whole document replacement with empty JSON pointers.
23
     */
24 3 View Code Duplication
    protected function handleObject($srcStruct, $desStruct, $path)
0 ignored issues
show
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...
25
    {
26 3
        $changes = [];
27
28 3
        foreach ($desStruct as $key => $val) {
29 3
            if (!property_exists($srcStruct, $key)) {
30 1
                $changes[] = $this->makePatch(self::OP_ADD, $this->path($path, $key), $val);
31 3
            } elseif ($srcStruct->$key != $val) {
32 2
                $changes = array_merge($changes, $this->makeDiff($srcStruct->$key, $val, $this->path($path, $key)));
33 2
            }
34 3
        }
35
36 3
        if ($this->shouldPartiallyReplace($desStruct, $srcStruct)) {
37 2
            foreach ($srcStruct as $key => $val) {
38 2
                if (!property_exists($desStruct, $key)) {
39 1
                    $changes[] = $this->makePatch(self::OP_REMOVE, $this->path($path, $key));
40 1
                }
41 2
            }
42 2
        }
43
44 3
        return $changes;
45
    }
46
47 2
    protected function handleArray($srcStruct, $desStruct, $path)
48
    {
49 2
        $changes = [];
50
51 2
        if ($srcStruct != $desStruct) {
52 2
            if ($diff = $this->arrayDiff($desStruct, $srcStruct)) {
0 ignored issues
show
Unused Code introduced by
$diff 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...
53 1
                $changes[] = $this->makePatch(self::OP_REPLACE, $path, $desStruct);
54 1
            }
55 2
            foreach ($srcStruct as $key => $val) {
56 1
                if (!in_array($val, $desStruct, true)) {
57 1
                    $changes[] = $this->makePatch(self::OP_REMOVE, $this->path($path, $key));
58 1
                }
59 2
            }
60 2
        }
61
62 2
        return $changes;
63
    }
64
}