ErrorCodeProvider::getErrorCodes()   B
last analyzed

Complexity

Conditions 7
Paths 11

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 12
c 1
b 0
f 0
nc 11
nop 1
dl 0
loc 24
rs 8.8333
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Getnet\PaymentMagento\Gateway\Validator;
12
13
use PaymentMagento\Result\Error;
0 ignored issues
show
Bug introduced by
The type PaymentMagento\Result\Error 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
use PaymentMagento\Result\Successful;
0 ignored issues
show
Bug introduced by
The type PaymentMagento\Result\Successful 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...
15
use PaymentMagento\Transaction;
0 ignored issues
show
Bug introduced by
The type PaymentMagento\Transaction 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...
16
17
/**
18
 * Class ErrorCodeProvider - Handles return from gateway.
19
 */
20
class ErrorCodeProvider
21
{
22
    /**
23
     * Error list.
24
     *
25
     * @param Successful|Error $response
26
     *
27
     * @return array
28
     */
29
    public function getErrorCodes($response): array
30
    {
31
        $result = [];
32
        if (!$response instanceof Error) {
33
            return $result;
34
        }
35
36
        $collection = $response->errors;
37
38
        foreach ($collection->deepAll() as $error) {
39
            $result[] = $error->code;
40
        }
41
42
        if (isset($response->transaction) && $response->transaction) {
43
            if ($response->transaction->status === Transaction::GATEWAY_REJECTED) {
44
                $result[] = $response->transaction->gatewayRejectionReason;
45
            }
46
47
            if ($response->transaction->status === Transaction::PROCESSOR_DECLINED) {
48
                $result[] = $response->transaction->processorResponseCode;
49
            }
50
        }
51
52
        return $result;
53
    }
54
}
55