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.

JsonPatch   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 60
Duplicated Lines 36.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 22
loc 60
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A disableRestrictedPropRemovals() 0 10 4
C handleObject() 22 22 7
B handleArray() 0 17 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types=1);
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): array
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(\stdClass $srcStruct, \stdClass $desStruct, string $path): array
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) {
0 ignored issues
show
Bug introduced by
The expression $desStruct of type object<stdClass> is not traversable.
Loading history...
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) {
0 ignored issues
show
Bug introduced by
The expression $srcStruct of type object<stdClass> is not traversable.
Loading history...
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(array $srcStruct, array $desStruct, string $path): array
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
}
65