ProductUpdate   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 96.1%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 94
ccs 74
cts 77
cp 0.961
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 91 2
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
class ProductUpdate implements ConfigurationInterface
16
{
17 2
    public function getConfigTreeBuilder()
18
    {
19 2
        $treeBuilder = new TreeBuilder('shapin_stripe');
20 2
        $rootNode = $treeBuilder->getRootNode();
21
22
        $rootNode
23 2
            ->children()
24 2
                ->booleanNode('active')
25 2
                    ->info('Whether the product is available for purchase.')
26 2
                ->end()
27 2
                ->arrayNode('attributes')
28 2
                    ->scalarPrototype()->end()
29 2
                    ->info('A list of up to 5 alphanumeric attributes that each SKU can provide values for (e.g., ["color", "size"]). If a value for attributes is specified, the list specified will replace the existing attributes list on this product. Any attributes not present after the update will be deleted from the SKUs for this product. This will be unset if you POST an empty value.')
30 2
                    ->validate()
31
                        ->ifTrue(function ($c) {
32 1
                            return 5 < \count($c);
33 2
                        })
34 2
                        ->thenInvalid('You can have up to 5 attributes.')
35 2
                    ->end()
36 2
                ->end()
37 2
                ->scalarNode('caption')
38 2
                    ->info('A short one-line description of the product, meant to be displayable to the customer.')
39 2
                ->end()
40 2
                ->arrayNode('deactivate_on')
41 2
                    ->prototype('scalar')->end()
42 2
                    ->info('An array of Connect application names or identifiers that should not be able to order the SKUs for this product. This will be unset if you POST an empty value.')
43 2
                ->end()
44 2
                ->scalarNode('description')
45 2
                    ->info('The product’s description, meant to be displayable to the customer.')
46 2
                ->end()
47 2
                ->arrayNode('images')
48 2
                    ->scalarPrototype()->end()
49 2
                    ->info('A list of up to 8 URLs of images for this product, meant to be displayable to the customer. This will be unset if you POST an empty value.')
50 2
                    ->validate()
51
                        ->ifTrue(function ($c) {
52 1
                            return 8 < \count($c);
53 2
                        })
54 2
                        ->thenInvalid('You can have up to 8 images.')
55 2
                    ->end()
56 2
                ->end()
57 2
                ->arrayNode('metadata')
58 2
                    ->scalarPrototype()->end()
59 2
                    ->info('A set of key-value pairs that you can attach to a product object. It can be useful for storing additional information about the product in a structured format.')
60 2
                ->end()
61 2
                ->scalarNode('name')
62 2
                    ->info('The product’s name, meant to be displayable to the customer. Applicable to both service and good types.')
63 2
                ->end()
64 2
                ->arrayNode('package_dimensions')
65 2
                    ->children()
66 2
                        ->floatNode('height')
67 2
                            ->isRequired()
68 2
                            ->info('Height, in inches. Maximum precision is 2 decimal places.')
69 2
                        ->end()
70 2
                        ->floatNode('length')
71 2
                            ->isRequired()
72 2
                            ->info('Length, in inches. Maximum precision is 2 decimal places.')
73 2
                        ->end()
74 2
                        ->floatNode('weight')
75 2
                            ->isRequired()
76 2
                            ->info('Weight, in ounces. Maximum precision is 2 decimal places.')
77 2
                        ->end()
78 2
                        ->floatNode('width')
79 2
                            ->isRequired()
80 2
                            ->info('Width, in inches. Maximum precision is 2 decimal places.')
81 2
                        ->end()
82 2
                    ->end()
83 2
                    ->info('The dimensions of this product for shipping purposes. A SKU associated with this product can override this value by having its own package_dimensions.')
84 2
                ->end()
85 2
                ->booleanNode('shippable')
86 2
                    ->info('Whether this product is shipped (i.e., physical goods). Defaults to true.')
87 2
                ->end()
88 2
                ->scalarNode('url')
89 2
                    ->info('A URL of a publicly-accessible webpage for this product.')
90 2
                ->end()
91 2
            ->end()
92
        ;
93
94
        $rootNode
95 2
            ->validate()
96
                ->always(function ($c) {
97
                    if (empty($c['deactivate_on'])) {
98
                        unset($c['deactivate_on']);
99
                    }
100
101
                    return $c;
102 2
                })
103 2
            ->end()
104
        ;
105
106 2
        return $treeBuilder;
107
    }
108
}
109