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 ( bde994...6bcf7a )
by Jamie
12:13
created

Object   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 144
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 6
Metric Value
wmc 10
c 7
b 1
f 6
lcom 1
cbo 4
dl 32
loc 144
ccs 44
cts 44
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A populateFromResponse() 10 10 1
A getPublicUri() 0 4 1
A create() 0 5 1
A retrieve() 0 5 1
A download() 0 5 1
A delete() 0 4 1
A copy() 0 5 1
A mergeMetadata() 11 11 1
A resetMetadata() 11 11 1
A getMetadata() 0 5 1

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
2
3
namespace OpenStack\ObjectStore\v1\Models;
4
5
use OpenStack\Common\Transport\Utils;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\StreamInterface;
8
use OpenStack\Common\Resource\AbstractResource;
9
use OpenStack\Common\Resource\Creatable;
10
use OpenStack\Common\Resource\Deletable;
11
use OpenStack\Common\Resource\HasMetadata;
12
13
/**
14
 * @property \OpenStack\ObjectStore\v1\Api $api
15
 */
16
class Object extends AbstractResource implements Creatable, Deletable, HasMetadata
17
{
18
    use MetadataTrait;
19
20
    const METADATA_PREFIX = 'X-Object-Meta-';
21
22
    /** @var string */
23
    public $containerName;
24
25
    /** @var string */
26
    public $name;
27
28
    /** @var string */
29
    public $hash;
30
31
    /** @var string */
32
    public $contentType;
33
34
    /** @var int */
35
    public $contentLength;
36
37
    /** @var string */
38
    public $lastModified;
39
40
    /** @var array */
41
    public $metadata;
42
43
    protected $markerKey = 'name';
44
    protected $aliases = ['bytes' => 'contentLength'];
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 4 View Code Duplication
    public function populateFromResponse(ResponseInterface $response)
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...
50
    {
51 4
        parent::populateFromResponse($response);
52
53 4
        $this->hash = $response->getHeaderLine('ETag');
54 4
        $this->contentLength = $response->getHeaderLine('Content-Length');
0 ignored issues
show
Documentation Bug introduced by
The property $contentLength was declared of type integer, but $response->getHeaderLine('Content-Length') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
55 4
        $this->lastModified = $response->getHeaderLine('Last-Modified');
56 4
        $this->contentType = $response->getHeaderLine('Content-Type');
57 4
        $this->metadata = $this->parseMetadata($response);
58 4
    }
59
60
    /**
61
     * Retrieves the public URI for this resource.
62
     *
63
     * @return \GuzzleHttp\Psr7\Uri
64
     */
65 1
    public function getPublicUri()
66
    {
67 1
        return Utils::addPaths($this->getHttpBaseUrl(), $this->containerName, $this->name);
0 ignored issues
show
Documentation introduced by
$this->containerName is of type string, but the function expects a array<integer,?>.

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...
Unused Code introduced by
The call to Utils::addPaths() has too many arguments starting with $this->name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
68
    }
69
70
    /**
71
     * @param array $data {@see \OpenStack\ObjectStore\v1\Api::putObject}
72
     *
73
     * @return $this
74
     */
75 2
    public function create(array $data)
76
    {
77 2
        $response = $this->execute($this->api->putObject(), $data + ['containerName' => $this->containerName]);
78 2
        return $this->populateFromResponse($response);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 3
    public function retrieve()
85
    {
86 3
        $response = $this->executeWithState($this->api->headObject());
87 2
        $this->populateFromResponse($response);
88 2
    }
89
90
    /**
91
     * This call will perform a `GET` HTTP request for the given object and return back its content in the form of a
92
     * Guzzle Stream object. Downloading an object will transfer all of the content for an object, and is therefore
93
     * distinct from fetching its metadata (a `HEAD` request). The body of an object is not fetched by default to
94
     * improve performance when handling large objects.
95
     *
96
     * @return StreamInterface
97
     */
98 1
    public function download()
99
    {
100 1
        $response = $this->executeWithState($this->api->getObject());
101 1
        return $response->getBody();
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 1
    public function delete()
108
    {
109 1
        $this->executeWithState($this->api->deleteObject());
110 1
    }
111
112
    /**
113
     * @param array $options {@see \OpenStack\ObjectStore\v1\Api::copyObject}
114
     */
115 1
    public function copy(array $options)
116
    {
117 1
        $options += ['name' => $this->name, 'containerName' => $this->containerName];
118 1
        $this->execute($this->api->copyObject(), $options);
119 1
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 1 View Code Duplication
    public function mergeMetadata(array $metadata)
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...
125
    {
126
        $options = [
127 1
            'containerName' => $this->containerName,
128 1
            'name'          => $this->name,
129 1
            'metadata'      => array_merge($metadata, $this->getMetadata()),
130 1
        ];
131
132 1
        $response = $this->execute($this->api->postObject(), $options);
133 1
        return $this->parseMetadata($response);
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139 1 View Code Duplication
    public function resetMetadata(array $metadata)
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...
140
    {
141
        $options = [
142 1
            'containerName'  => $this->containerName,
143 1
            'name'           => $this->name,
144 1
            'metadata'       => $metadata,
145 1
        ];
146
147 1
        $response = $this->execute($this->api->postObject(), $options);
148 1
        return $this->parseMetadata($response);
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154 2
    public function getMetadata()
155
    {
156 2
        $response = $this->executeWithState($this->api->headObject());
157 2
        return $this->parseMetadata($response);
158
    }
159
}
160