Conditions | 6 |
Paths | 6 |
Total Lines | 53 |
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->canCapture()) { |
||
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::captureMode($record->Gateway)) { |
||
57 | case GatewayInfo::MULTIPLE: |
||
58 | $infoText = 'MultiCaptureInfo'; |
||
59 | break; |
||
60 | case GatewayInfo::PARTIAL: |
||
61 | $infoText = 'SingleCaptureInfo'; |
||
62 | break; |
||
63 | case GatewayInfo::FULL: |
||
64 | $infoText = 'FullCaptureInfo'; |
||
65 | break; |
||
66 | } |
||
67 | |||
68 | /** @var DBMoney $money */ |
||
69 | $money = $record->dbObject('Money'); |
||
70 | $money->setAmount($record->getMaxCaptureAmount()); |
||
71 | |||
72 | /** @var GridField_FormAction $field */ |
||
73 | $field = GridField_FormAction::create( |
||
74 | $gridField, |
||
75 | 'CapturePayment' . $record->ID, |
||
76 | false, |
||
77 | 'capturepayment', |
||
78 | array('RecordID' => $record->ID) |
||
79 | ) |
||
80 | ->addExtraClass('gridfield-button-capture payment-dialog-button') |
||
81 | ->setAttribute('title', _t('GridFieldCaptureAction.Title', 'Capture Payment')) |
||
82 | ->setAttribute('data-icon', 'button-capture') |
||
83 | ->setAttribute('data-dialog', json_encode(array( |
||
84 | 'maxAmount' => $money->Nice(), |
||
85 | 'maxAmountNum' => $money->getAmount(), |
||
86 | 'hasAmountField' => $record->canCapture(null, true), |
||
87 | 'infoTextKey' => $infoText, |
||
88 | 'buttonTextKey' => 'CaptureAmount' |
||
89 | ))) |
||
90 | ->setDescription(_t('GridFieldCaptureAction.Description', 'Capture authorized Payment')); |
||
91 | |||
92 | return $field->Field(); |
||
93 | } |
||
94 | |||
135 |