Conditions | 2 |
Paths | 2 |
Total Lines | 132 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 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 |
||
66 | public function updateCMSFields(FieldList $fields) |
||
67 | { |
||
68 | |||
69 | //// Favicons Tab |
||
70 | |||
71 | $tab = 'Root.Metadata.Favicons'; |
||
72 | |||
73 | //// Favicon |
||
74 | |||
75 | $fields->addFieldsToTab($tab, array( |
||
76 | LabelField::create('FaviconDescription', 'Favicons are `favourite icons` used by browsers in a number of ways whenever an icon is necessary e.g. tabs, history, bookmarks, dashboards.<br />@ <a href="https://en.wikipedia.org/wiki/Favicon" target="_blank">Favicon - Wikipedia, the free encyclopedia</a>') |
||
77 | ->addExtraClass('information') |
||
78 | )); |
||
79 | |||
80 | //// HTML4 Favicon |
||
81 | |||
82 | // check favicon.ico & set status |
||
83 | $icoStatus = ReadonlyField::create('HTML4FaviconStatus', 'Favicon ICO<pre>type: ico</pre><pre>size: (multiple)<br />16x16 & 32x32 & 64x64 px</pre>', 'favicon.ico error'); |
||
84 | if (Director::fileExists('favicon.ico')) { |
||
85 | $icoStatus |
||
86 | ->setValue('favicon.ico found') |
||
87 | ->addExtraClass('success favicon'); |
||
88 | } else { |
||
89 | $icoStatus |
||
90 | ->setValue('favicon.ico not found') |
||
91 | ->addExtraClass('error'); |
||
92 | } |
||
93 | |||
94 | // header & fields |
||
95 | $fields->addFieldsToTab($tab, array( |
||
96 | HeaderField::create('HTML4FaviconHeader', 'HTML4 <span class="aka">( favicon.ico )</span>'), |
||
97 | LabelField::create('HTML4FaviconDescription', 'It is recommended you simply have a `favicon.ico` file in the webroot.') |
||
98 | ->addExtraClass('information'), |
||
99 | $icoStatus |
||
100 | )); |
||
101 | |||
102 | //// HTML5 Favicon |
||
103 | |||
104 | // header & fields |
||
105 | $fields->addFieldsToTab($tab, array( |
||
106 | HeaderField::create('HTML5FaviconHeader', 'HTML5 <span class="aka">( favicon.png )</span>'), |
||
107 | LabelField::create('HTML5FaviconDescription', '@todo Description') |
||
108 | ->addExtraClass('information'), |
||
109 | UploadField::create('HTML5Favicon', 'Favicon PNG<pre>type: png</pre><pre>size: 192x192 px</pre>') |
||
110 | ->setAllowedExtensions(array('png')) |
||
111 | ->setFolderName(self::$SEOIconsUpload) |
||
112 | )); |
||
113 | |||
114 | //// Pinned Icons Tab |
||
115 | |||
116 | $tab = 'Root.Metadata.PinnedIcons'; |
||
117 | |||
118 | //// Pinned Icons Information |
||
119 | |||
120 | $fields->addFieldsToTab($tab, array( |
||
121 | LabelField::create('PiniconDescription', 'Pinned icons are OS-specific desktop shortcuts to pages on your website, they allow you to configure additional theming options to make pages appear more `native` / `web-app-y` within the OS.<br />Given they are OS-specific, they (obviously!) have a different format for each one :(') |
||
122 | ->addExtraClass('information') |
||
123 | )); |
||
124 | |||
125 | //// Pinned Icon Title |
||
126 | |||
127 | // CMS fields |
||
128 | $fields->addFieldsToTab($tab, array( |
||
129 | // header |
||
130 | HeaderField::create('PiniconTitleHeader', 'Pinned Icon Title <span class="aka">( a.k.a. App Name )</span>'), |
||
131 | // description |
||
132 | LabelField::create('PiniconTitleDescription', 'When adding a link to the home screen, the user can choose a caption. By default, this is the bookmarked page title, which is usually fine. However, iOS and Windows 8 let you override this default value.') |
||
133 | ->addExtraClass('information'), |
||
134 | TextField::create('PiniconTitle', 'Application Title') |
||
135 | ->setAttribute('placeholder', 'default: page title') |
||
136 | )); |
||
137 | |||
138 | //// iOS Pinned Icon |
||
139 | |||
140 | // CMS fields |
||
141 | $fields->addFieldsToTab($tab, array( |
||
142 | // header |
||
143 | HeaderField::create('IOSPiniconHeader', 'iOS Pinned Icon <span class="aka">( a.k.a. Touch Icons, Web Clips )</span>'), |
||
144 | // information |
||
145 | LabelField::create('IOSPiniconDescription', 'iPhone and iPad users can pin your web site on their home screen. The link looks like a native app.<br />@ <a href="https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html" target="_blank">Configuring Web Applications - iOS Developer Library</a>') |
||
146 | ->addExtraClass('information'), |
||
147 | // icon |
||
148 | UploadField::create('IOSPinicon', 'iOS Icon<pre>type: png</pre><pre>size: 192x192 px</pre>') |
||
149 | ->setAllowedExtensions(array('png')) |
||
150 | ->setFolderName(self::$SEOIconsUpload) |
||
151 | ->setDescription('iOS will fill the transparent regions with black by default, so put your own background in!') |
||
152 | )); |
||
153 | |||
154 | //// Android Pinned Icon |
||
155 | |||
156 | // CMS fields |
||
157 | $fields->addFieldsToTab($tab, array( |
||
158 | // header |
||
159 | HeaderField::create('AndroidPiniconHeader', 'Android Pinned Icon <span class="aka">( a.k.a. Android Chrome Icons, Launcher Icons )</span>'), |
||
160 | // information |
||
161 | LabelField::create('AndroidPiniconDescription', 'Add to Homescreen is a also a feature of Android Chrome. Your visitors can mix their natives apps and web bookmarks.<br />@ <a href="https://developer.chrome.com/multidevice/android/installtohomescreen" target="_blank">Add to Homescreen - Google Chrome</a>') |
||
162 | ->addExtraClass('information'), |
||
163 | // icon |
||
164 | UploadField::create('AndroidPinicon', 'Android Icon<pre>type: png</pre><pre>size: 192x192 px</pre>') |
||
165 | ->setAllowedExtensions(array('png')) |
||
166 | ->setFolderName(self::$SEOIconsUpload), |
||
167 | // background |
||
168 | TextField::create('AndroidPiniconThemeColor', 'Theme Color<pre>type: hex triplet</pre>') |
||
169 | ->setAttribute('placeholder', 'none') |
||
170 | ->setAttribute('size', 6) |
||
171 | ->setMaxLength(6) |
||
172 | ->setDescription('Starting with Android Lollipop, you can customize the color of the task bar in the switcher.') |
||
173 | )); |
||
174 | |||
175 | //// Windows Pinned Icon |
||
176 | |||
177 | // CMS fields |
||
178 | $fields->addFieldsToTab($tab, array( |
||
179 | // header |
||
180 | HeaderField::create('WindowsShortcutHeader', 'Windows Pinned Icon <span class="aka">( a.k.a. Windows 8 / Metro Tiles )</span>'), |
||
181 | // information |
||
182 | LabelField::create('WindowsShortcutDescription', 'Windows 8 users can pin your web site on their desktop. Your site appears as a tile, just like a native Windows 8 app.<br />@ <a href="https://msdn.microsoft.com/en-us/library/dn455106" target="_blank">Creating custom tiles for IE11 websites (Windows)</a>') |
||
183 | ->addExtraClass('information'), |
||
184 | // icon |
||
185 | UploadField::create('WindowsPinicon', 'Windows Icon<pre>type: png</pre><pre>size: 192x192 px</pre>') |
||
186 | ->setAllowedExtensions(array('png')) |
||
187 | ->setFolderName(self::$SEOIconsUpload), |
||
188 | // background |
||
189 | TextField::create('WindowsPiniconBackgroundColor', 'Background ( Tile ) Color<pre>type: hex triplet</pre>') |
||
190 | ->setAttribute('placeholder', 'none') |
||
191 | ->setAttribute('size', 6) |
||
192 | ->setMaxLength(6) |
||
193 | )); |
||
194 | |||
195 | // @todo Safari Pinned Tab ~ maybe ?? |
||
196 | |||
197 | } |
||
198 | |||
366 |
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.