Passed
Pull Request — master (#9)
by Daniel
03:17
created

TransactionEndpoint::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 8
rs 10
1
<?php
2
namespace CodeCloud\Bundle\ShopifyBundle\Api\Endpoint;
3
4
use CodeCloud\Bundle\ShopifyBundle\Api\GenericResource;
5
use CodeCloud\Bundle\ShopifyBundle\Api\Request\GetJson;
6
use CodeCloud\Bundle\ShopifyBundle\Api\Request\PostJson;
7
8
class TransactionEndpoint extends AbstractEndpoint
9
{
10
    /**
11
     * @param int $orderId
12
     * @param array $query
13
     * @return array|GenericEntity
0 ignored issues
show
Bug introduced by
The type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
     */
15
    public function findByOrder($orderId, array $query = array())
16
    {
17
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions.json', $query);
18
        $response = $this->send($request);
19
        return $this->createCollection($response->get('transactions'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('transactions') 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('transactions'));
Loading history...
20
    }
21
22
    /**
23
     * @param int $orderId
24
     * @return int
25
     */
26
    public function countByOrder($orderId)
27
    {
28
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions/count.json');
29
        $response = $this->send($request);
30
        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...
31
    }
32
33
    /**
34
     * @param int $orderId
35
     * @param int $transactionId
36
     * @param array $fields
37
     * @return GenericEntity
38
     */
39
    public function findOne($orderId, $transactionId, array $fields = array())
40
    {
41
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
42
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions/' . $transactionId . '.json', $params);
43
        $response = $this->send($request);
44
        return $this->createEntity($response->get('transaction'));
0 ignored issues
show
Bug introduced by
It seems like $response->get('transaction') 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

44
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('transaction'));
Loading history...
Bug Best Practice introduced by
The expression return $this->createEnti...se->get('transaction')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
45
    }
46
47
    /**
48
     * @param int $orderId
49
     * @param float|null $amount
50
     */
51
    public function capture($orderId, $amount = null)
52
    {
53
        $params = array('kind' => 'capture');
54
55
        if ($amount) {
56
            $params['amount'] = (float)$amount;
57
        }
58
59
        $request = new PostJson('/admin/orders/' . $orderId . '/transactions.json', array('transaction' => $params));
60
        $this->send($request);
61
    }
62
63
    /**
64
     * @param int $orderId
65
     * @param GenericResource $transaction
66
     * @return GenericEntity
67
     */
68
    public function create($orderId, GenericResource $transaction)
69
    {
70
        $request = new PostJson('/admin/orders/' . $orderId . '/transactions.json', array(
71
            'transaction' => $transaction->toArray(),
72
        ));
73
        $response = $this->send($request);
74
75
        return $this->createEntity($response->get('transaction'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createEnti...se->get('transaction')) returns the type CodeCloud\Bundle\ShopifyBundle\Api\GenericResource which is incompatible with the documented return type CodeCloud\Bundle\Shopify...\Endpoint\GenericEntity.
Loading history...
Bug introduced by
It seems like $response->get('transaction') 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

75
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('transaction'));
Loading history...
76
    }
77
}
78