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

ParseResponse::normalizeResponse()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.1967

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 20
ccs 10
cts 13
cp 0.7692
rs 9.2
c 1
b 0
f 0
cc 4
eloc 11
nc 8
nop 1
crap 4.1967
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
}