| Conditions | 5 |
| Paths | 1 |
| Total Lines | 87 |
| Code Lines | 58 |
| 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 |
||
| 68 | public function getCMSFields() |
||
| 69 | { |
||
| 70 | // PHP 5.3 only |
||
| 71 | $self = $this; |
||
| 72 | $this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) { |
||
| 73 | // Don't put the GridField for documents in until the set has been created |
||
| 74 | if (!$self->isInDB()) { |
||
| 75 | $fields->addFieldToTab( |
||
| 76 | 'Root.Main', |
||
| 77 | LiteralField::create( |
||
| 78 | 'GridFieldNotice', |
||
| 79 | '<p class="message warning">' . _t( |
||
| 80 | 'DMSDocumentSet.GRIDFIELD_NOTICE', |
||
| 81 | 'Managing documents will be available once you have created this document set.' |
||
| 82 | ) . '</p>' |
||
| 83 | ), |
||
| 84 | 'Title' |
||
| 85 | ); |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | // Document listing |
||
| 90 | $gridFieldConfig = GridFieldConfig::create() |
||
| 91 | ->addComponents( |
||
| 92 | new GridFieldToolbarHeader(), |
||
| 93 | new GridFieldFilterHeader(), |
||
| 94 | new GridFieldSortableHeader(), |
||
| 95 | // new GridFieldOrderableRows('DocumentSort'), |
||
| 96 | new GridFieldDataColumns(), |
||
| 97 | new GridFieldEditButton(), |
||
| 98 | // Special delete dialog to handle custom behaviour of unlinking and deleting |
||
| 99 | new DMSGridFieldDeleteAction(), |
||
| 100 | new GridFieldDetailForm() |
||
| 101 | ); |
||
| 102 | |||
| 103 | if (class_exists('GridFieldPaginatorWithShowAll')) { |
||
| 104 | $paginatorComponent = new GridFieldPaginatorWithShowAll(15); |
||
| 105 | } else { |
||
| 106 | $paginatorComponent = new GridFieldPaginator(15); |
||
| 107 | } |
||
| 108 | $gridFieldConfig->addComponent($paginatorComponent); |
||
| 109 | |||
| 110 | if (class_exists('GridFieldSortableRows')) { |
||
| 111 | $sortableComponent = new GridFieldSortableRows('DocumentSort'); |
||
| 112 | // setUsePagenation method removed from newer version of SortableGridField. |
||
| 113 | if (method_exists($sortableComponent, 'setUsePagination')) { |
||
| 114 | $sortableComponent->setUsePagination(false)->setForceRedraw(true); |
||
| 115 | } |
||
| 116 | $gridFieldConfig->addComponent($sortableComponent); |
||
| 117 | } |
||
| 118 | |||
| 119 | // HACK: Create a singleton of DMSDocument to ensure extensions are applied before we try to get display fields. |
||
| 120 | singleton(self::$linked_document_type); |
||
| 121 | $gridFieldConfig->getComponentByType('GridFieldDataColumns') |
||
| 122 | ->setDisplayFields(Config::inst()->get('DMSDocument', 'display_fields')) |
||
| 123 | ->setFieldCasting(array('LastChanged' => 'Datetime->Ago')) |
||
| 124 | ->setFieldFormatting( |
||
| 125 | array( |
||
| 126 | 'FilenameWithoutID' => '<a target=\'_blank\' class=\'file-url\' href=\'$Link\'>$FilenameWithoutID</a>', |
||
| 127 | ) |
||
| 128 | ); |
||
| 129 | |||
| 130 | // Override delete functionality with this class |
||
| 131 | $gridFieldConfig->getComponentByType('GridFieldDetailForm') |
||
| 132 | ->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest'); |
||
| 133 | $gridField = GridField::create( |
||
| 134 | 'Documents', |
||
| 135 | false, |
||
| 136 | $self->Documents(), |
||
| 137 | $gridFieldConfig |
||
| 138 | ); |
||
| 139 | $gridField->setModelClass('DMSDocument'); |
||
| 140 | $gridField->addExtraClass('documents'); |
||
| 141 | |||
| 142 | $gridFieldConfig->addComponent( |
||
| 143 | $addNewButton = new DMSGridFieldAddNewButton, |
||
| 144 | 'GridFieldExportButton' |
||
| 145 | ); |
||
| 146 | $addNewButton->setDocumentSetId($self->ID); |
||
| 147 | |||
| 148 | $fields->removeByName('Documents'); |
||
| 149 | $fields->addFieldToTab('Root.Main', $gridField); |
||
| 150 | $this->addQueryFields($fields); |
||
| 151 | }); |
||
| 152 | $this->addRequirements(); |
||
| 153 | return parent::getCMSFields(); |
||
| 154 | } |
||
| 155 | |||
| 268 |
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.