CustomerCreate::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 101

Duplication

Lines 101
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 101
loc 101
ccs 0
cts 95
cp 0
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Shapin\Stripe\Configuration;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15 View Code Duplication
class CustomerCreate implements ConfigurationInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    public function getConfigTreeBuilder()
18
    {
19
        $treeBuilder = new TreeBuilder('shapin_stripe_customer_create');
20
        $rootNode = $treeBuilder->getRootNode();
21
22
        $rootNode
23
            ->children()
24
                ->integerNode('account_balance')
25
                    ->info('An integer amount in pence that represents the account balance for your customer. Account balances only affect invoices. A negative amount represents a credit that decreases the amount due on an invoice; a positive amount increases the amount due on an invoice.')
26
                ->end()
27
                ->scalarNode('coupon')
28
                    ->info('The code of the coupon to apply to this subscription. A coupon applied to a subscription will only affect invoices created for that particular subscription. This can be unset by updating the value to null and then saving.')
29
                ->end()
30
                ->scalarNode('default_source')
31
                    ->info('ID of the default payment source for the customer.')
32
                ->end()
33
                ->scalarNode('description')
34
                    ->info('An arbitrary string that you can attach to a customer object. It is displayed alongside the customer in the dashboard. This can be unset by updating the value to null and then saving.')
35
                ->end()
36
                ->scalarNode('email')
37
                    ->info('Customer’s email address. It’s displayed alongside the customer in your dashboard and can be useful for searching and tracking. This may be up to 512 characters. This can be unset by updating the value to null and then saving.')
38
                ->end()
39
                ->scalarNode('invoice_prefix')
40
                    ->info('The prefix for the customer used to generate unique invoice numbers. Must be 3–12 uppercase letters or numbers.')
41
                ->end()
42
                ->arrayNode('invoice_settings')
43
                    ->children()
44
                        ->arrayNode('custom_fields')
45
                            ->arrayPrototype()
46
                                ->children()
47
                                    ->scalarNode('name')
48
                                        ->isRequired()
49
                                        ->info('The name of the custom field. This may be up to 30 characters.')
50
                                    ->end()
51
                                    ->scalarNode('value')
52
                                        ->isRequired()
53
                                        ->info('The value of the custom field. This may be up to 30 characters.')
54
                                    ->end()
55
                                ->end()
56
                            ->end()
57
                            ->info('Default custom fields to be displayed on invoices for this customer.')
58
                        ->end()
59
                        ->scalarNode('footer')
60
                            ->info('Default footer to be displayed on invoices for this customer. This can be unset by updating the value to null and then saving.')
61
                        ->end()
62
                    ->end()
63
                    ->info('Default invoice settings for this customer.')
64
                ->end()
65
                ->arrayNode('metadata')
66
                    ->scalarPrototype()->end()
67
                    ->info('A set of key-value pairs that you can attach to a customer object. It can be useful for storing additional information about the customer in a structured format.')
68
                ->end()
69
                ->arrayNode('shipping')
70
                    ->children()
71
                        ->arrayNode('address')
72
                            ->isRequired()
73
                            ->children()
74
                                ->scalarNode('line1')
75
                                    ->isRequired()
76
                                    ->cannotBeEmpty()
77
                                ->end()
78
                                ->scalarNode('city')->end()
79
                                ->scalarNode('country')->end()
80
                                ->scalarNode('line2')->end()
81
                                ->scalarNode('postal_code')->end()
82
                                ->scalarNode('state')->end()
83
                            ->end()
84
                            ->info('Customer shipping address.')
85
                        ->end()
86
                        ->scalarNode('name')
87
                            ->isRequired()
88
                            ->cannotBeEmpty()
89
                            ->info('Customer name. This can be unset by updating the value to null and then saving.')
90
                        ->end()
91
                        ->scalarNode('phone')
92
                            ->info('Customer phone (including extension). This can be unset by updating the value to null and then saving.')
93
                        ->end()
94
                    ->end()
95
                    ->info('The customer’s shipping information. Appears on invoices emailed to this customer.')
96
                ->end()
97
                ->scalarNode('source')
98
                    ->info('The source can either be a Token or a Source, as returned by Elements, or a associative array containing a user’s credit card details (with the options shown below). You must provide a source if the customer does not already have a valid source attached, and you are subscribing the customer to be charged automatically for a plan that is not free. Passing source will create a new source object, make it the customer default source, and delete the old customer default if one exists. If you want to add an additional source, instead use the card creation API to add the card and then the customer update API to set it as the default. Whenever you attach a card to a customer, Stripe will automatically validate the card.')
99
                ->end()
100
                ->arrayNode('tax_info')
101
                    ->children()
102
                        ->scalarNode('tax_id')
103
                            ->isRequired(true)
104
                            ->info('The customer’s tax ID number. This can be unset by updating the value to null and then saving.')
105
                        ->end()
106
                        ->scalarNode('type')
107
                            ->isRequired(true)
108
                            ->info('The type of ID number. The only possible value is vat')
109
                        ->end()
110
                    ->end()
111
                    ->info('The customer’s tax information. Appears on invoices emailed to this customer.')
112
                ->end()
113
            ->end()
114
        ;
115
116
        return $treeBuilder;
117
    }
118
}
119