Completed
Pull Request — master (#6)
by Rafael
04:31
created

PartnerClient::partnerCancelOrderOnVenture()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 0
cp 0
rs 9.4286
cc 2
eloc 8
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Iris\Api;
4
5
class PartnerClient extends BaseClient
6
{
7
    /**
8
     * Partner Create Order on External Shop
9
     *
10
     * @param string $ventureCode
11
     * @param array $orderData
12
     * @return bool
13
     */
14 2
    public function createOrderOnVenture($ventureCode, $orderData)
15
    {
16
        try {
17 2
            $this->doRequest(
18 2
                'post',
19 2
                $this->buildRequestUrl('/fulfillment/order/create', $ventureCode),
20 2
                array('body' => json_encode($orderData))
21 2
            );
22 2
        } catch (\Exception $e) {
23 1
            $this->throwException(
24 1
                $e,
0 ignored issues
show
Documentation introduced by
$e is of type object<Exception>, but the function expects a object<Iris\Api\RequestException>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25 1
                'Unable to create order on Externalshop',
0 ignored issues
show
Unused Code introduced by
The call to PartnerClient::throwException() has too many arguments starting with 'Unable to create order on Externalshop'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
26 1
                ['VentureCode' => $ventureCode, 'OrderData' => $orderData]
27 1
            );
28
        }
29 2
        return true;
30
    }
31
32
    /**
33
     * Partner Confirm Paid Order on External Shop
34
     *
35
     * @param string $ventureCode
36
     * @param int    $orderNumber
37
     * @return bool
38
     */
39 2
    public function confirmPaymentOnVenture($ventureCode, $orderNumber)
40
    {
41
        try {
42 2
            $this->doRequest(
43 2
                'put',
44 2
                $this->buildRequestUrl(sprintf('/fulfillment/order/confirm/%s', $orderNumber), $ventureCode)
45 2
            );
46 2
        } catch (\Exception $e) {
47 1
            $this->throwException(
48 1
                $e,
0 ignored issues
show
Documentation introduced by
$e is of type object<Exception>, but the function expects a object<Iris\Api\RequestException>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49 1
                'Unable to confirm payment for venture on Externalshop',
0 ignored issues
show
Unused Code introduced by
The call to PartnerClient::throwException() has too many arguments starting with 'Unable to confirm payme...enture on Externalshop'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
50 1
                ['VentureCode' => $ventureCode, 'OrderNr' => $orderNumber]
51 1
            );
52
        }
53 2
        return true;
54
    }
55
56
    /**
57
     * Partner Cancel Order on External Shop
58
     *
59
     * @param string $ventureCode
60
     * @param int    $orderNumber
61
     * @return bool
62
     */
63 2
    public function cancelOrderOnVenture($ventureCode, $orderNumber)
64
    {
65
        try {
66 2
            $this->doRequest(
67 2
                'put',
68 2
                $this->buildRequestUrl(sprintf('/fulfillment/order/cancel/%s', $orderNumber), $ventureCode)
69 2
            );
70 2
        } catch (\Exception $e) {
71 1
            $this->throwException(
72 1
                $e,
0 ignored issues
show
Documentation introduced by
$e is of type object<Exception>, but the function expects a object<Iris\Api\RequestException>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
73 1
                'Unable to cancel order on Externalshop',
0 ignored issues
show
Unused Code introduced by
The call to PartnerClient::throwException() has too many arguments starting with 'Unable to cancel order on Externalshop'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
74 1
                ['VentureCode' => $ventureCode, 'OrderNr' => $orderNumber]
75 1
            );
76
        }
77 2
        return true;
78
    }
79
80
    /**
81
     * Partner Confirm Paid Order on External Shop
82
     * @param string $ventureCode
83
     * @param int $orderNumber
84
     * @return bool
85
     */
86
    public function partnerConfirmPaymentForVenture($ventureCode, $orderNumber)
87
    {
88
        try {
89
            $this->doRequest(
90
                'put',
91
                $this->buildRequestUrl(sprintf('/fulfillment/order/confirm/%s', $orderNumber), $ventureCode)
92
            );
93
        } catch (RequestException $e) {
0 ignored issues
show
Bug introduced by
The class Iris\Api\RequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
94
            $this->throwException($e);
95
        }
96
        return true;
97
    }
98
99
    /**
100
     * Partner Cancel Order on External Shop
101
     * @param string $ventureCode
102
     * @param int $orderNumber
103
     * @return bool
104
     */
105
    public function partnerCancelOrderOnVenture($ventureCode, $orderNumber)
106
    {
107
        try {
108
            $this->doRequest(
109
                'put',
110
                $this->buildRequestUrl(sprintf('/fulfillment/order/cancel/%s', $orderNumber), $ventureCode)
111
            );
112
        } catch (RequestException $e) {
0 ignored issues
show
Bug introduced by
The class Iris\Api\RequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
113
            $this->throwException($e);
114
        }
115
        return true;
116
    }
117
118
    /**
119
     * @param RequestException $e
120
     * @throw Iris_Service_Exception_RetryMessage
121
     */
122
    private function throwException(RequestException $e)
123
    {
124
        Bob_Log::exception($e);
125
        $message = 'Try Again';
126
        $code = 500;
127
        if ($e->hasResponse()) {
128
            $this->logResponse($e->getResponse());
129
            $message = $e->getResponse()->getBody();
130
            $code = $e->getResponse()->getStatusCode();
131
        }
132
        throw new Iris_Service_Exception_RetryMessage($message, $code);
133
    }
134
}
135