Conditions | 10 |
Paths | 9 |
Total Lines | 105 |
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 |
||
16 | public function updateCMSFields(FieldList $fields) |
||
17 | { |
||
18 | if ($this->owner instanceof Folder || !$this->owner->ID) { |
||
|
|||
19 | return; |
||
20 | } |
||
21 | |||
22 | $fields->addFieldToTab('Root.Main', new ReadonlyField( |
||
23 | 'VersionNumber', |
||
24 | _t('VersionedFiles.CURRENTVERSION', 'Current Version') |
||
25 | ), 'Created'); |
||
26 | |||
27 | |||
28 | // History |
||
29 | |||
30 | $gridFieldConfig = GridFieldConfig::create()->addComponents( |
||
31 | new GridFieldToolbarHeader(), |
||
32 | //new GridFieldFilterHeader(), |
||
33 | new GridFieldSortableHeader(), |
||
34 | new GridFieldDataColumns(), |
||
35 | new GridFieldPaginator(15), |
||
36 | new GridFieldViewButton(), |
||
37 | //new GridFieldDeleteAction(), |
||
38 | new GridFieldDetailForm() |
||
39 | ); |
||
40 | |||
41 | $gridField = new GridField('Versions', 'Versions', $this->owner->Versions(), $gridFieldConfig); |
||
42 | $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); |
||
43 | $columns->setDisplayFields(array( |
||
44 | 'VersionNumber' => _t('VersionedFiles.VERSIONNUMBER', 'Version Number'), |
||
45 | 'Creator.Name' => _t('VersionedFiles.CREATOR', 'Creator'), |
||
46 | 'Created' => _t('VersionedFiles.DATE', 'Date'), |
||
47 | 'Link' => _t('VersionedFiles.LINK', 'Link'), |
||
48 | 'IsCurrent' => _t('VersionedFiles.ISCURRENT', 'Is Current') |
||
49 | )); |
||
50 | |||
51 | $columns->setFieldCasting(array( |
||
52 | 'Created' => 'Date->Nice' |
||
53 | )); |
||
54 | |||
55 | $columns->setFieldFormatting(array( |
||
56 | 'Link' => '<a href=\"$URL\" target=\"_blank\">$Name</a>', |
||
57 | 'IsCurrent' => '{$IsCurrent()->Nice()}', |
||
58 | 'Created' => '{$obj(\'Created\')->Nice()}' |
||
59 | )); |
||
60 | |||
61 | // history |
||
62 | |||
63 | $versions = $this->owner->Versions( |
||
64 | sprintf('"VersionNumber" <> %d', $this->getVersionNumber()) |
||
65 | ); |
||
66 | |||
67 | if ($versions && $versions->Count() && $this->owner->canEdit()) { |
||
68 | $fields->addFieldToTab('Root.History', new HeaderField('RollbackHeader', _t('VersionedFiles.ROLLBACKPREVVERSION', 'Rollback to a Previous Version'))); |
||
69 | $fields->addFieldToTab('Root.History', $versionDropdown = new DropdownField('PreviousVersion', '', $versions->map('VersionNumber'))); |
||
70 | $versionDropdown->setEmptyString(_t('VersionedFiles.SELECTAVERSION', '(Select a Version)')); |
||
71 | } |
||
72 | |||
73 | $fields->addFieldToTab('Root.History', $gridField); |
||
74 | |||
75 | // Replace |
||
76 | if (!$this->owner->config()->get('disableReplaceTab')) { |
||
77 | if (!$this->owner->canEdit()) { |
||
78 | return; |
||
79 | } |
||
80 | |||
81 | $folder = $this->owner->Parent(); |
||
82 | $uploadField = new VersionedFileUploadField('ReplacementFile', ''); |
||
83 | $uploadField->setConfig('previewMaxWidth', 40); |
||
84 | $uploadField->setConfig('previewMaxHeight', 30); |
||
85 | $uploadField->setConfig('allowedMaxFileNumber', 1); |
||
86 | $uploadField->addExtraClass('ss-assetuploadfield'); |
||
87 | $uploadField->removeExtraClass('ss-uploadfield'); |
||
88 | $uploadField->setTemplate('VersionedFileUploadField'); |
||
89 | $uploadField->currentVersionFile = $this->owner; |
||
90 | $uploadField->relationAutoSetting = false; |
||
91 | $uploadField->setOverwriteWarning(false); |
||
92 | |||
93 | if ($folder->exists() && $folder->getFilename()) { |
||
94 | $path = preg_replace('/^' . ASSETS_DIR . '\//', '', $folder->getFilename()); |
||
95 | $uploadField->setFolderName($path); |
||
96 | } else { |
||
97 | $uploadField->setFolderName(ASSETS_DIR); |
||
98 | } |
||
99 | |||
100 | // set the valid extensions to only that of the original file |
||
101 | $ext = strtolower($this->owner->Extension); |
||
102 | $uploadField->getValidator()->setAllowedExtensions(array($ext)); |
||
103 | |||
104 | // css / js requirements for asset admin style file uploader |
||
105 | Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js'); |
||
106 | Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css'); |
||
107 | |||
108 | $fields->addFieldToTab('Root.Replace', $uploadField); |
||
109 | |||
110 | |||
111 | $sameTypeMessage = sprintf(_t( |
||
112 | 'VersionedFiles.SAMETYPEMESSAGE', |
||
113 | 'You may only replace this file with another of the same type: .%s' |
||
114 | ), $this->owner->getExtension()); |
||
115 | |||
116 | $fields->addFieldToTab('Root.Replace', new LiteralField('SameTypeMessage', "<p>$sameTypeMessage</p>")); |
||
117 | } |
||
118 | |||
119 | return; |
||
120 | } |
||
121 | |||
311 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.