Passed
Push — main ( b21561...f38fd7 )
by Iain
09:13 queued 04:17
created

StartSubscriptionResponse::createPaymentFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2024 Iain Cambridge
7
 *
8
 *     This program is free software: you can redistribute it and/or modify
9
 *     it under the terms of the GNU General Public License as published by
10
 *     the Free Software Foundation, either version 3 of the License, or
11
 *     (at your option) any later version.
12
 *
13
 *     This program is distributed in the hope that it will be useful,
14
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *     GNU General Public License for more details.
17
 *
18
 *     You should have received a copy of the GNU General Public License
19
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon\Billing\Response;
23
24
use Parthenon\Billing\Entity\Subscription;
25
use Symfony\Component\Validator\ConstraintViolationInterface;
26
use Symfony\Component\Validator\ConstraintViolationListInterface;
27
28
class StartSubscriptionResponse
29
{
30
    public const CODE_REQUEST_INVALID = '320000';
31
    public const CODE_NO_BILLING_DETAILS = '320001';
32
    public const CODE_UNSUPPORTED_PAYMENT_PROVIDER = '320002';
33
    public const CODE_PLAN_NOT_FOUND = '320003';
34
    public const CODE_PLAN_PRICE_NOT_FOUND = '320004';
35
    public const CODE_GENERAL_ERROR = '320005';
36
    public const CODE_PAYMENT_FAILURE_ERROR = '320006';
37
    public const CODE_NO_PAYMENT_DETAILS_ERROR = '320007';
38
39
    public static function createGeneralError(): array
40
    {
41
        return [
42
            'success' => false,
43
            'code' => static::CODE_GENERAL_ERROR,
44
        ];
45
    }
46
47
    public static function createInvalidRequestResponse(ConstraintViolationListInterface $errors): array
48
    {
49
        $errorOutput = [];
50
51
        /** @var ConstraintViolationInterface $error */
52
        foreach ($errors as $error) {
53
            $errorOutput[$error->getPropertyPath()] = $error->getMessage();
54
        }
55
56
        return [
57
            'success' => false,
58
            'code' => static::CODE_REQUEST_INVALID,
59
            'errors' => $errorOutput,
60
        ];
61
    }
62
63
    public static function createNoBillingDetails(): array
64
    {
65
        return [
66
            'success' => false,
67
            'code' => static::CODE_NO_BILLING_DETAILS,
68
        ];
69
    }
70
71
    public static function createUnsupportedPaymentProvider(): array
72
    {
73
        return [
74
            'success' => false,
75
            'code' => static::CODE_UNSUPPORTED_PAYMENT_PROVIDER,
76
        ];
77
    }
78
79
    public static function createPlanNotFound(): array
80
    {
81
        return [
82
            'success' => false,
83
            'code' => static::CODE_PLAN_NOT_FOUND,
84
        ];
85
    }
86
87
    public static function createPlanPriceNotFound(): array
88
    {
89
        return [
90
            'success' => false,
91
            'code' => static::CODE_PLAN_PRICE_NOT_FOUND,
92
        ];
93
    }
94
95
    public static function createPaymentFailed(): array
96
    {
97
        return [
98
            'success' => false,
99
            'code' => static::CODE_PAYMENT_FAILURE_ERROR,
100
        ];
101
    }
102
103
    public static function createNoPaymentDetails(): array
104
    {
105
        return [
106
            'success' => false,
107
            'code' => static::CODE_NO_PAYMENT_DETAILS_ERROR,
108
        ];
109
    }
110
111
    public static function createSuccessResponse(Subscription $subscription): array
0 ignored issues
show
Unused Code introduced by
The parameter $subscription is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

111
    public static function createSuccessResponse(/** @scrutinizer ignore-unused */ Subscription $subscription): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
112
    {
113
        return [
114
            'success' => true,
115
        ];
116
    }
117
}
118