ProvinceEndpoint::findOne()   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\GetJson;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PutJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
7
8
class ProvinceEndpoint extends AbstractEndpoint
9
{
10
    /**
11
     * @param int $countryId
12
     * @param array $query
13
     * @return array|GenericResource[]
14
     */
15
    public function findByCountry($countryId, array $query = array())
16
    {
17
        $request = new GetJson('/admin/countries/' . $countryId . '/provinces.json', $query);
18
        $response = $this->send($request);
19
        return $this->createCollection($response->get('provinces'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('provinces') 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

19
        return $this->createCollection(/** @scrutinizer ignore-type */ $response->get('provinces'));
Loading history...
20
    }
21
22
    /**
23
     * @param int $countryId
24
     * @param array $query
25
     * @return int
26
     */
27
    public function countByCountry($countryId, array $query = array())
28
    {
29
        $request = new GetJson('/admin/countries/' . $countryId . '/provinces.json', $query);
30
        $response = $this->send($request);
31
        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...
32
    }
33
34
    /**
35
     * @param int $countryId
36
     * @param int $provinceId
37
     * @return GenericResource
38
     */
39
    public function findOne($countryId, $provinceId)
40
    {
41
        $request = new GetJson('/admin/countries/' . $countryId . '/provinces/' . $provinceId . '.json');
42
        $response = $this->send($request);
43
        return $this->createEntity($response->get('province'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('province') 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('province'));
Loading history...
44
    }
45
46
    /**
47
     * @param int $countryId
48
     * @param int $provinceId
49
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $province
50
     * @return GenericResource
51
     */
52
    public function update($countryId, $provinceId, GenericResource $province)
53
    {
54
        $request = new PutJson('/admin/countries/' . $countryId . '/provinces/' . $provinceId . '.json', array('province' => $province->toArray()));
55
        $response = $this->send($request);
56
        return $this->createEntity($response->get('province'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('province') 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

56
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('province'));
Loading history...
57
    }
58
}
59