Products   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 68
ccs 7
cts 7
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getProduct() 0 4 1
A getProducts() 0 4 1
request() 0 1 ?
A setSandboxProduct() 0 6 1
1
<?php namespace Stevenmaguire\Uber\Resources;
2
3
trait Products
4
{
5
    /**
6
     * Fetches a specific product.
7
     *
8
     * @param    string   $productId    Product id
9
     *
10
     * @return   stdClass               The JSON response from the request
11
     *
12
     * @see      https://developer.uber.com/docs/riders/references/api/v1.2/products-product_id-get
13
     */
14 2
    public function getProduct($productId)
15
    {
16 2
        return $this->request('get', 'products/'.$productId);
17
    }
18
19
    /**
20
     * Lists available products.
21
     *
22
     * The Products endpoint returns information about the Uber products
23
     * offered at a given location. The response includes the display name and
24
     * other details about each product, and lists the products in the proper
25
     * display order.
26
     *
27
     * Some Products, such as experiments or promotions such as UberPOOL and
28
     * UberFRESH, will not be returned by this endpoint.
29
     *
30
     * @param    array    $attributes   Query attributes
31
     *
32
     * @return   stdClass               The JSON response from the request
33
     *
34
     * @see      https://developer.uber.com/docs/riders/references/api/v1.2/products-get
35
     */
36 8
    public function getProducts($attributes = [])
37
    {
38 8
        return $this->request('get', 'products', $attributes);
39
    }
40
41
    /**
42
     * Makes a request to the Uber API and returns the response.
43
     *
44
     * @param    string $verb       The Http verb to use
45
     * @param    string $path       The path of the APi after the domain
46
     * @param    array  $parameters Parameters
47
     *
48
     * @return   stdClass The JSON response from the request
49
     * @throws   Exception
50
     */
51
    abstract protected function request($verb, $path, $parameters = []);
52
53
    /**
54
     * Updates a specific product properties for sandbox responses.
55
     *
56
     * @param    string   $productId    Product id
57
     * @param    array    $attributes   Query attributes
58
     *
59
     * @return   stdClass               The JSON response from the request
60
     * @throws   Exception
61
     *
62
     * @see      https://developer.uber.com/docs/riders/guides/sandbox#product-types
63
     */
64 4
    public function setSandboxProduct($productId, $attributes = [])
65
    {
66 4
        $this->enforceSandboxExpectation();
0 ignored issues
show
Bug introduced by
It seems like enforceSandboxExpectation() 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...
67
68 2
        return $this->request('put', 'sandbox/products/'.$productId, $attributes);
69
    }
70
}
71