Issues (193)

src/Api/Endpoint/ProductImageEndpoint.php (5 issues)

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 ProductImageEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @param int $productId
14
     * @param array $query
15
     * @return array|\CodeCloud\Bundle\ShopifyBundle\Api\GenericResource[]
16
     */
17
    public function findByProduct($productId, array $query = array())
18
    {
19
        $request = new GetJson('/admin/products/' . $productId . '/images.json', $query);
20
        $response = $this->send($request);
21
        return $this->createCollection($response->get('images'));
0 ignored issues
show
It seems like $response->get('images') can also be of type string; however, parameter $items of CodeCloud\Bundle\Shopify...int::createCollection() 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

21
        return $this->createCollection(/** @scrutinizer ignore-type */ $response->get('images'));
Loading history...
22
    }
23
24
    /**
25
     * @param int $productId
26
     * @param array $query
27
     * @return int
28
     */
29
    public function countByProduct($productId, array $query = array())
30
    {
31
        $request = new GetJson('/admin/products/' . $productId . '/images/count.json', $query);
32
        $response = $this->send($request);
33
        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...
34
    }
35
36
    /**
37
     * @param int $productId
38
     * @param int $productImageId
39
     * @return GenericResource
40
     */
41
    public function findOne($productId, $productImageId, array $fields = array())
42
    {
43
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
44
        $request = new GetJson('/admin/products/' . $productId . '/images/' . $productImageId . '.json', $params);
45
        $response = $this->send($request);
46
        return $this->createEntity($response->get('image'));
0 ignored issues
show
It seems like $response->get('image') 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

46
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('image'));
Loading history...
47
    }
48
49
    /**
50
     * @param int $productId
51
     * @param GenericResource $productImage
52
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
53
     */
54
    public function create($productId, GenericResource $productImage)
55
    {
56
        $request = new PostJson('/admin/products/' . $productId . '/images.json', array('image' => $productImage->toArray()));
57
        $response = $this->send($request);
58
        return $this->createEntity($response->get('image'));
0 ignored issues
show
It seems like $response->get('image') 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

58
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('image'));
Loading history...
59
    }
60
61
    /**
62
     * @param int $productId
63
     * @param int $productImageId
64
     * @param GenericResource $productImage
65
     * @return GenericResource
66
     */
67
    public function update($productId, $productImageId, GenericResource $productImage)
68
    {
69
        $request = new PutJson('/admin/products/' . $productId . '/images/' . $productImageId . '.json', array('image' => $productImage->toArray()));
70
        $response = $this->send($request);
71
        return $this->createEntity($response->get('image'));
0 ignored issues
show
It seems like $response->get('image') 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

71
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('image'));
Loading history...
72
    }
73
74
    /**
75
     * @param int $productId
76
     * @param int $productImageId
77
     */
78
    public function delete($productId, $productImageId)
79
    {
80
        $request = new DeleteParams('/admin/products/' . $productId . '/images/' . $productImageId . '.json');
81
        $this->send($request);
82
    }
83
}
84