ProductVariantEndpoint::findByProduct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\Request\DeleteParams;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson;
7
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
8
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
9
10
class ProductVariantEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param int $productId
14
     * @param array $query
15
     * @return array|GenericResource[]
16
     */
17
    public function findByProduct($productId, array $query = array())
18
    {
19
        $request = new GetJson('/admin/products/' . $productId . '/variants.json', $query);
20
        $response = $this->sendPaged($request, 'variants');
21
        return $this->createCollection($response);
22
    }
23
24
    /**
25
     * @param int $productId
26
     * @return int
27
     */
28
    public function countByProduct($productId)
29
    {
30
        $request = new GetJson('/admin/products/' . $productId . '/variants/count.json');
31
        $response = $this->send($request);
32
        return $response->get('count');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $response->get('count') also could return the type string which is incompatible with the documented return type integer.
Loading history...
33
    }
34
35
    /**
36
     * @param int $variantId
37
     * @return GenericResource
38
     */
39
    public function findOne($variantId)
40
    {
41
        $request = new GetJson('/admin/variants/' . $variantId . '.json');
42
        $response = $this->send($request);
43
        return $this->createEntity($response->get('variant'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('variant') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('variant'));
Loading history...
44
    }
45
46
    /**
47
     * @param int $productId
48
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $variant
49
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
50
     */
51
    public function create($productId, GenericResource $variant)
52
    {
53
        $request = new PostJson('/admin/products/' . $productId . '/variants.json', array('variant' => $variant->toArray()));
54
        $response = $this->send($request);
55
        return $this->createEntity($response->get('variant'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('variant') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('variant'));
Loading history...
56
    }
57
58
    /**
59
     * @param int $variantId
60
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $variant
61
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
62
     */
63
    public function update($variantId, GenericResource $variant)
64
    {
65
        $request = new PutJson('/admin/variants/' . $variantId . '.json', array('variant' => $variant->toArray()));
66
        $response = $this->send($request);
67
        return $this->createEntity($response->get('variant'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('variant') can also be of type string; however, parameter $data of CodeCloud\Bundle\Shopify...ndpoint::createEntity() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('variant'));
Loading history...
68
    }
69
70
    /**
71
     * @param int $variantId
72
     */
73
    public function delete($variantId)
74
    {
75
        $request = new DeleteParams('/admin/variants/' . $variantId . '.json');
76
        $this->send($request);
77
    }
78
}
79