Conditions | 6 |
Paths | 6 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function getColumnContent($gridField, $record, $columnName) |
||
42 | { |
||
43 | if (!($record instanceof Payment)) { |
||
44 | return null; |
||
45 | } |
||
46 | |||
47 | if (!$record->canRefund()) { |
||
48 | return null; |
||
49 | } |
||
50 | |||
51 | Requirements::css('bummzack/silverstripe-omnipay-ui: client/dist/css/omnipay-ui-cms.css'); |
||
52 | Requirements::javascript('bummzack/silverstripe-omnipay-ui: client/dist/javascript/omnipay-ui-cms.js'); |
||
53 | Requirements::add_i18n_javascript('bummzack/silverstripe-omnipay-ui: client/dist/javascript/lang'); |
||
54 | |||
55 | $infoText = ''; |
||
56 | switch (GatewayInfo::refundMode($record->Gateway)) { |
||
57 | case GatewayInfo::MULTIPLE: |
||
58 | $infoText = 'MultiRefundInfo'; |
||
59 | break; |
||
60 | case GatewayInfo::PARTIAL: |
||
61 | $infoText = 'SingleRefundInfo'; |
||
62 | break; |
||
63 | case GatewayInfo::FULL: |
||
64 | $infoText = 'FullRefundInfo'; |
||
65 | break; |
||
66 | } |
||
67 | |||
68 | /** @var DBMoney $money */ |
||
69 | $money = $record->dbObject('Money'); |
||
70 | |||
71 | /** @var GridField_FormAction $field */ |
||
72 | $field = GridField_FormAction::create( |
||
73 | $gridField, |
||
74 | 'RefundPayment' . $record->ID, |
||
75 | false, |
||
76 | 'refundpayment', |
||
77 | array('RecordID' => $record->ID) |
||
78 | ) |
||
79 | ->addExtraClass('gridfield-button-refund payment-dialog-button') |
||
80 | ->setAttribute('title', _t('GridFieldRefundAction.Title', 'Refund Payment')) |
||
81 | ->setAttribute('data-icon', 'button-refund') |
||
82 | ->setAttribute('data-dialog', json_encode(array( |
||
83 | 'maxAmount' => $money->Nice(), |
||
84 | 'maxAmountNum' => $money->getAmount(), |
||
85 | 'hasAmountField' => $record->canRefund(null, true), |
||
86 | 'infoTextKey' => $infoText, |
||
87 | 'buttonTextKey' => 'RefundAmount' |
||
88 | ))) |
||
89 | ->setDescription(_t('GridFieldRefundAction.Description', 'Refund a captured payment')); |
||
90 | |||
91 | return $field->Field(); |
||
92 | } |
||
93 | |||
134 |