CountryEndpoint::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 1
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 CountryEndpoint extends AbstractEndpoint
11
{
12
    /**
13
     * @return array|GenericResource[]
14
     */
15
    public function findAll()
16
    {
17
        $request = new GetJson('/admin/countries.json');
18
        $response = $this->send($request);
19
        return $this->createCollection($response->get('countries'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('countries') 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('countries'));
Loading history...
20
    }
21
22
    /**
23
     * @return int
24
     */
25
    public function countAll()
26
    {
27
        $request = new GetJson('/admin/countries/count.json');
28
        $response = $this->send($request);
29
        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...
30
    }
31
32
    /**
33
     * @param int $countryId
34
     * @return GenericResource
35
     */
36
    public function findOne($countryId)
37
    {
38
        $request = new GetJson('/admin/countries/' . $countryId . '.json');
39
        $response = $this->send($request);
40
        return $this->createEntity($response->get('country'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('country') 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

40
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('country'));
Loading history...
41
    }
42
43
    /**
44
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $country
45
     * @return \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource
46
     */
47
    public function create(GenericResource $country)
48
    {
49
        $request = new PostJson('/admin/countries.json', array('country' => $country->toArray()));
50
        $response = $this->send($request);
51
        return $this->createEntity($response->get('country'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('country') 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

51
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('country'));
Loading history...
52
    }
53
54
    /**
55
     * @param int $countryId
56
     * @param \CodeCloud\Bundle\ShopifyBundle\Api\GenericResource $country
57
     * @return GenericResource
58
     */
59
    public function update($countryId, GenericResource $country)
60
    {
61
        $request = new PutJson('/admin/countries/' . $countryId . '.json', array('country' => $country->toArray()));
62
        $response = $this->send($request);
63
        return $this->createEntity($response->get('country'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('country') 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

63
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('country'));
Loading history...
64
    }
65
66
    /**
67
     * @param int $countryId
68
     */
69
    public function delete($countryId)
70
    {
71
        $request = new DeleteParams('/admin/countries/' . $countryId . '.json');
72
        $this->send($request);
73
    }
74
}
75