TransactionEndpoint::capture()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
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\PostJson;
6
7
class TransactionEndpoint extends AbstractEndpoint
8
{
9
    /**
10
     * @param int $orderId
11
     * @param array $query
12
     * @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...
13
     */
14
    public function findByOrder($orderId, array $query = array())
15
    {
16
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions.json', $query);
17
        $response = $this->send($request);
18
        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

18
        return $this->createCollection(/** @scrutinizer ignore-type */ $response->get('transactions'));
Loading history...
19
    }
20
21
    /**
22
     * @param int $orderId
23
     * @return int
24
     */
25
    public function countByOrder($orderId)
26
    {
27
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions/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 $orderId
34
     * @param int $transactionId
35
     * @param array $fields
36
     * @return GenericEntity
37
     */
38
    public function findOne($orderId, $transactionId, array $fields = array())
39
    {
40
        $params = $fields ? array('fields' => implode(',', $fields)) : array();
41
        $request = new GetJson('/admin/orders/' . $orderId . '/transactions/' . $transactionId . '.json', $params);
42
        $response = $this->send($request);
43
        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

43
        return $this->createEntity(/** @scrutinizer ignore-type */ $response->get('transaction'));
Loading history...
44
    }
45
46
    /**
47
     * @param int $orderId
48
     * @param float|null $amount
49
     */
50
    public function capture($orderId, $amount = null)
51
    {
52
        $params = array('kind' => 'capture');
53
54
        if ($amount) {
55
            $params['amount'] = (float)$amount;
56
        }
57
58
        $request = new PostJson('/admin/orders/' . $orderId . '/transactions.json', array('transaction' => $params));
59
        $this->send($request);
60
    }
61
}
62