GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Factory::getException()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Netaxept API package.
5
 *
6
 * (c) Andrew Plank
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace FDM\Netaxept\Exception;
15
16
use Webmozart\Assert\Assert;
17
18
class Factory
19
{
20
    private $classMap = [];
21
22
    public function __construct(
23
        $authenticationExceptionClass = AuthenticationException::class,
24
        $bbsExceptionClass = BBSException::class,
25
        $genericErrorClass = GenericError::class,
26
        $merchantTranslationExceptionClass = MerchantTranslationException::class,
27
        $notSupportedExceptionClass = NotSupportedException::class,
28
        $queryExceptionClass = QueryException::class,
29
        $securityExceptionClass = SecurityException::class,
30
        $uniqueTransactionIdExceptionClass = UniqueTransactionIdException::class,
31
        $validationExceptionClass = ValidationException::class,
32
        $transactionNotFoundExceptionClass = TransactionNotFoundException::class,
33
        $transactionNotAuthorizedExceptionClass = TransactionNotAuthorizedException::class
34
    ) {
35
        $this->classMap = [
36
            'AuthenticationException' => $authenticationExceptionClass,
37
            'BBSException' => $bbsExceptionClass,
38
            'GenericError' => $genericErrorClass,
39
            'MerchantTranslationException' => $merchantTranslationExceptionClass,
40
            'NotSupportedException' => $notSupportedExceptionClass,
41
            'SecurityException' => $securityExceptionClass,
42
            'UniqueTransactionIdException' => $uniqueTransactionIdExceptionClass,
43
            'ValidationException' => $validationExceptionClass,
44
            'QueryException' => $queryExceptionClass,
45
            'TransactionNotFoundException' => $transactionNotFoundExceptionClass,
46
            'TransactionNotAuthorizedException' => $transactionNotAuthorizedExceptionClass,
47
        ];
48
    }
49
50
    public function getException(\SimpleXMLElement $xml): Exception
51
    {
52
        $exceptionType = (string) $xml->Error->attributes('xsi', true)->type;
53
54
        switch ($xml->Error->Message) {
55
            case 'Unable to find transaction':
56
                $exceptionType = 'TransactionNotFoundException';
57
58
            break;
59
60
            case 'You cannot run capture on a transaction that never is authorized':
61
                $exceptionType = 'TransactionNotAuthorizedException';
62
63
            break;
64
        }
65
66
        Assert::notEmpty(
67
            $this->classMap[$exceptionType],
68
            'Unable to instantiate Exception class for ' . $exceptionType
69
        );
70
71
        $exceptionClass = $this->classMap[$exceptionType];
72
73
        throw new $exceptionClass($xml);
74
    }
75
}
76