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.

Account::populateFromResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace OpenStack\ObjectStore\v1\Models;
4
5
use OpenStack\Common\Resource\OperatorResource;
6
use OpenStack\Common\Resource\HasMetadata;
7
use OpenStack\Common\Resource\Retrievable;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * @property \OpenStack\ObjectStore\v1\Api $api
12
 */
13
class Account extends OperatorResource implements Retrievable, HasMetadata
14
{
15
    use MetadataTrait;
16
17
    const METADATA_PREFIX = 'X-Account-Meta-';
18
19
    /** @var int */
20
    public $objectCount;
21
22
    /** @var int */
23
    public $bytesUsed;
24
25
    /** @var int */
26
    public $containerCount;
27
28
    /** @var array */
29
    public $metadata;
30
31
    /** @var string */
32
    public $tempUrl;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2 View Code Duplication
    public function populateFromResponse(ResponseInterface $response): self
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...
38
    {
39 2
        parent::populateFromResponse($response);
40
41 2
        $this->containerCount = $response->getHeaderLine('X-Account-Container-Count');
0 ignored issues
show
Documentation Bug introduced by
The property $containerCount was declared of type integer, but $response->getHeaderLine...count-Container-Count') 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...
42 2
        $this->objectCount = $response->getHeaderLine('X-Account-Object-Count');
0 ignored issues
show
Documentation Bug introduced by
The property $objectCount was declared of type integer, but $response->getHeaderLine...-Account-Object-Count') 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...
43 2
        $this->bytesUsed = $response->getHeaderLine('X-Account-Bytes-Used');
0 ignored issues
show
Documentation Bug introduced by
The property $bytesUsed was declared of type integer, but $response->getHeaderLine('X-Account-Bytes-Used') 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...
44 2
        $this->tempUrl = $response->getHeaderLine('X-Account-Meta-Temp-URL-Key');
45 2
        $this->metadata = $this->parseMetadata($response);
46 2
47
        return $this;
48
    }
49
50
    /**
51 1
     * {@inheritdoc}
52
     */
53 1
    public function retrieve()
54 1
    {
55 1
        $response = $this->execute($this->api->headAccount());
56
        $this->populateFromResponse($response);
57
    }
58
59
    /**
60 1
     * {@inheritdoc}
61
     */
62 1
    public function mergeMetadata(array $metadata)
63 1
    {
64
        $response = $this->execute($this->api->postAccount(), ['metadata' => $metadata]);
65
        $this->metadata = $this->parseMetadata($response);
66
    }
67
68
    /**
69 1
     * {@inheritdoc}
70
     */
71 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...
72 1
    {
73 1
        $options = [
74 1
            'removeMetadata' => [],
75
            'metadata'       => $metadata,
76 1
        ];
77 1
78 1
        foreach ($this->getMetadata() as $key => $val) {
79 1
            if (!array_key_exists($key, $metadata)) {
80 1
                $options['removeMetadata'][$key] = 'True';
81
            }
82 1
        }
83 1
84
        $response = $this->execute($this->api->postAccount(), $options);
85
        $this->metadata = $this->parseMetadata($response);
86
    }
87
88
    /**
89 2
     * {@inheritdoc}
90
     */
91 2
    public function getMetadata(): array
92 2
    {
93
        $response = $this->execute($this->api->headAccount());
94
        return $this->parseMetadata($response);
95
    }
96
}
97