Conditions | 2 |
Paths | 2 |
Total Lines | 115 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
48 | public function schema($request) { |
||
49 | // TODO Hardcoding schema until we can get GridField to generate a schema dynamically |
||
50 | $json = <<<JSON |
||
51 | { |
||
52 | "id": "EditForm", |
||
53 | "schema": { |
||
54 | "name": "EditForm", |
||
55 | "id": "EditForm", |
||
56 | "action": "schema", |
||
57 | "method": "GET", |
||
58 | "schema_url": "admin\/campaigns\/schema\/EditForm", |
||
59 | "attributes": { |
||
60 | "id": "Form_EditForm", |
||
61 | "action": "admin\/campaigns\/EditForm", |
||
62 | "method": "POST", |
||
63 | "enctype": "multipart\/form-data", |
||
64 | "target": null, |
||
65 | "class": "cms-edit-form CampaignAdmin LeftAndMain" |
||
66 | }, |
||
67 | "data": [], |
||
68 | "fields": [{ |
||
69 | "name": "ID", |
||
70 | "id": "Form_EditForm_ID", |
||
71 | "type": "Hidden", |
||
72 | "component": null, |
||
73 | "holder_id": null, |
||
74 | "title": false, |
||
75 | "source": null, |
||
76 | "extraClass": "hidden nolabel", |
||
77 | "description": null, |
||
78 | "rightTitle": null, |
||
79 | "leftTitle": null, |
||
80 | "readOnly": false, |
||
81 | "disabled": false, |
||
82 | "customValidationMessage": "", |
||
83 | "attributes": [], |
||
84 | "data": [] |
||
85 | }, { |
||
86 | "name": "ChangeSets", |
||
87 | "id": "Form_EditForm_ChangeSets", |
||
88 | "type": "Custom", |
||
89 | "component": "GridField", |
||
90 | "holder_id": null, |
||
91 | "title": "Campaigns", |
||
92 | "source": null, |
||
93 | "extraClass": null, |
||
94 | "description": null, |
||
95 | "rightTitle": null, |
||
96 | "leftTitle": null, |
||
97 | "readOnly": false, |
||
98 | "disabled": false, |
||
99 | "customValidationMessage": "", |
||
100 | "attributes": [], |
||
101 | "data": { |
||
102 | "recordType": "ChangeSet", |
||
103 | "collectionReadEndpoint": { |
||
104 | "url": "admin\/campaigns\/sets", |
||
105 | "method": "GET" |
||
106 | }, |
||
107 | "itemReadEndpoint": { |
||
108 | "url": "admin\/campaigns\/set\/:id", |
||
109 | "method": "GET" |
||
110 | }, |
||
111 | "itemUpdateEndpoint": { |
||
112 | "url": "admin\/campaigns\/set\/:id", |
||
113 | "method": "PUT" |
||
114 | }, |
||
115 | "itemCreateEndpoint": { |
||
116 | "url": "admin\/campaigns\/set\/:id", |
||
117 | "method": "POST" |
||
118 | }, |
||
119 | "itemDeleteEndpoint": { |
||
120 | "url": "admin\/campaigns\/set\/:id", |
||
121 | "method": "DELETE" |
||
122 | }, |
||
123 | "editFormSchemaEndpoint": "admin\/campaigns\/schema\/DetailEditForm", |
||
124 | "columns": [ |
||
125 | {"name": "Title", "field": "Name"}, |
||
126 | {"name": "Changes", "field": "_embedded.ChangeSetItems.length"}, |
||
127 | {"name": "Description", "field": "Description"} |
||
128 | ] |
||
129 | } |
||
130 | }, { |
||
131 | "name": "SecurityID", |
||
132 | "id": "Form_EditForm_SecurityID", |
||
133 | "type": "Hidden", |
||
134 | "component": null, |
||
135 | "holder_id": null, |
||
136 | "title": "Security ID", |
||
137 | "source": null, |
||
138 | "extraClass": "hidden", |
||
139 | "description": null, |
||
140 | "rightTitle": null, |
||
141 | "leftTitle": null, |
||
142 | "readOnly": false, |
||
143 | "disabled": false, |
||
144 | "customValidationMessage": "", |
||
145 | "attributes": [], |
||
146 | "data": [] |
||
147 | }], |
||
148 | "actions": [] |
||
149 | } |
||
150 | } |
||
151 | JSON; |
||
152 | |||
153 | $formName = $request->param('ID'); |
||
154 | if($formName == 'EditForm') { |
||
155 | $response = $this->getResponse(); |
||
156 | $response->addHeader('Content-Type', 'application/json'); |
||
157 | $response->setBody($json); |
||
158 | return $response; |
||
159 | } else { |
||
160 | return parent::schema($request); |
||
161 | } |
||
162 | } |
||
163 | |||
422 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.