| Conditions | 4 |
| Paths | 8 |
| Total Lines | 66 |
| Code Lines | 44 |
| 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 |
||
| 97 | public function getCMSFields() |
||
| 98 | { |
||
| 99 | $fields = parent::getCMSFields(); |
||
| 100 | |||
| 101 | $config = GridFieldConfig_RelationEditor::create(); |
||
| 102 | $config->addComponent(new GridFieldSortableRows('SortOrder')); |
||
| 103 | |||
| 104 | $fields->addFieldsToTab( |
||
| 105 | 'Root.Main', |
||
| 106 | array( |
||
| 107 | NumericField::create('ServingCount', 'Servings per package') |
||
| 108 | ->setRightTitle('The number of servings in the jar/bucket/bottle/conatiner'), |
||
| 109 | TextField::create('Container', 'The product container') |
||
| 110 | ->setRightTitle('The conatiner for the product e.g. Jar, Bottle, Bucket'), |
||
| 111 | TextField::create('ServingSize', 'The size of each serving') |
||
| 112 | ->setRightTitle('The size of each serving e.g., 3g, 30ml'), |
||
| 113 | TextField::create('AdditionalInfo', 'Additional information') |
||
| 114 | ->setRightTitle('For example "Remove label with care."'), |
||
| 115 | ) |
||
| 116 | ); |
||
| 117 | |||
| 118 | $productsGrid = $fields->dataFieldByName('Products'); |
||
| 119 | if ($productsGrid) { |
||
| 120 | $productsFieldConfig = GridFieldConfig_RecordViewer::create(); |
||
| 121 | $productsGrid -> setConfig($productsFieldConfig); |
||
| 122 | } |
||
| 123 | |||
| 124 | $productVariationsGrid = $fields->dataFieldByName('ProductVariations'); |
||
| 125 | if ($productVariationsGrid) { |
||
| 126 | $productVariationsConfig = GridFieldConfig_RecordViewer::create(); |
||
| 127 | $productVariationsGrid -> setConfig($productVariationsConfig); |
||
| 128 | } |
||
| 129 | |||
| 130 | $nutriRowsGridField = $fields->dataFieldByName('NutriRows'); |
||
| 131 | |||
| 132 | if ($nutriRowsGridField) { |
||
| 133 | $nutriRowsFieldConfig = $nutriRowsGridField ->getConfig(); |
||
| 134 | $nutriRowsFieldConfig |
||
| 135 | ->addComponent(new GridFieldEditableColumns()) |
||
| 136 | ->addComponent(new GridFieldDeleteAction()) |
||
| 137 | ->addComponent(new GridFieldSortableRows('SortOrder')) |
||
| 138 | ->getComponentByType('GridFieldEditableColumns') |
||
| 139 | |||
| 140 | ->setDisplayFields( |
||
| 141 | array( |
||
| 142 | 'Title' => array( |
||
| 143 | 'title' => 'Item', |
||
| 144 | 'field' => 'ReadonlyField' |
||
| 145 | ), |
||
| 146 | 'PerServe' => array( |
||
| 147 | "title" => "Per Serve", |
||
| 148 | "callback" => function ($record, $column, $grid) { |
||
| 149 | return new TextField($column, "Serve"); |
||
| 150 | }), |
||
| 151 | |||
| 152 | 'Per100' => function ($record, $column, $grid) { |
||
| 153 | return new TextField($column, "Per 100"); |
||
| 154 | } |
||
| 155 | |||
| 156 | ) |
||
| 157 | ); |
||
| 158 | } |
||
| 159 | $fields->removeFieldFromTab('Root.Main', 'SortOrder'); |
||
| 160 | |||
| 161 | return $fields; |
||
| 162 | } |
||
| 163 | |||
| 191 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.