ShopConfigExtension::updateCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
dl 0
loc 51
rs 9.312
c 1
b 0
f 0
cc 1
nc 1
nop 1

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
namespace AntonyThorpe\SilvershopBankDeposit;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\SiteConfig\SiteConfig;
7
use SilverStripe\Forms\TextareaField;
8
use SilverStripe\Forms\TextField;
9
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
10
use SilverStripe\Forms\FieldList;
11
12
/**
13
 * @property ?string $BankAccountPaymentMethodMessage
14
 * @property ?string $BankAccountNumber
15
 * @property ?string $BankAccountDetails
16
 * @property ?string $BankAccountInvoiceMessage
17
 * @extends  Extension<SiteConfig&static>
18
 */
19
class ShopConfigExtension extends Extension
20
{
21
    private static array $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
22
        'BankAccountPaymentMethodMessage' => 'Text',
23
        'BankAccountNumber' => 'Text',
24
        'BankAccountDetails' => 'Text',
25
        'BankAccountInvoiceMessage' => 'HTMLText'
26
    ];
27
28
    public function updateCMSFields(FieldList $fieldList): void
29
    {
30
        $fieldList->addFieldsToTab(
31
            'Root.Shop.ShopTabs.' . _t('SilverShop\Extension\ShopConfigExtension.BankAccountTitle', 'Bank Account'),
32
            [
33
                Textfield::create(
34
                    "BankAccountPaymentMethodMessage",
35
                    _t(
36
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountPaymentMethodMessage",
37
                        "Payment Method message on Checkout page"
38
                    )
39
                )->setDescription(
40
                    _t(
41
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountPaymentMethodMessageDescription",
42
                        "Message to appear in the Payment Method section of Checkout Page"
43
                    )
44
                ),
45
                Textfield::create(
46
                    "BankAccountNumber",
47
                    _t(
48
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountNumber",
49
                        "Bank Account Number"
50
                    )
51
                )->setDescription(
52
                    _t(
53
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountNumberDescription",
54
                        "e.g XX-XXXX-XXXXXXX-XX"
55
                    )
56
                ),
57
                TextareaField::create(
58
                    "BankAccountDetails",
59
                    _t(
60
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountDetails",
61
                        "Bank Account Details"
62
                    )
63
                )->setDescription(
64
                    _t(
65
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountDetailsDescription",
66
                        "Account Name, Bank Name, Branch, Branch Address"
67
                    )
68
                ),
69
                HtmlEditorField::create(
70
                    "BankAccountInvoiceMessage",
71
                    _t(
72
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountInvoiceMessage",
73
                        "Bank Account Order/Invoice Message"
74
                    )
75
                )->setDescription(
76
                    _t(
77
                        "SilverShop\\Extension\\ShopConfigExtension.BankAccountInvoiceMessageDescription",
78
                        "Message to appear on the order/invoice"
79
                    )
80
                )
81
            ]
82
        );
83
    }
84
}
85