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