Passed
Push — master ( bf8804...0647e8 )
by Raza
01:40
created

ParseResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 76.92%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
ccs 10
cts 13
cp 0.7692
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalizeResponse() 0 20 4
1
<?php
2
3
namespace Srmklive\Dropbox;
4
5
trait ParseResponse
6
{
7
    /**
8
     * Parse response from Dropbox.
9
     *
10
     * @param array|\Psr\Http\Message\ResponseInterface $response
11
     *
12
     * @return array
13
     */
14 10
    protected function normalizeResponse($response)
15
    {
16 10
        $normalizedPath = ltrim($this->removePathPrefix($response['path_display']), '/');
0 ignored issues
show
Bug introduced by
It seems like removePathPrefix() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
17
18 10
        $normalizedResponse = ['path' => $normalizedPath];
19
20 10
        if (isset($response['server_modified'])) {
21 8
            $normalizedResponse['timestamp'] = strtotime($response['server_modified']);
22 8
        }
23
24 10
        if (isset($response['size'])) {
25
            $normalizedResponse['size'] = $response['size'];
26
            $normalizedResponse['bytes'] = $response['size'];
27
        }
28
29 10
        $type = ($response['.tag'] === 'folder' ? 'dir' : 'file');
30 10
        $normalizedResponse['type'] = $type;
31
32 10
        return $normalizedResponse;
33
    }
34
}