Conditions | 17 |
Paths | 421 |
Total Lines | 139 |
Code Lines | 100 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
37 | protected function getEditHtml() |
||
|
|||
38 | { |
||
39 | if (\CModule::IncludeModule('fileman')) { |
||
40 | ob_start(); |
||
41 | $codeType = $this->getContentTypeCode(); |
||
42 | /** @var string $className Имя класса без неймспейса */ |
||
43 | $className = $this->getEntityShortName(); |
||
44 | $entityClass = $this->entityName; |
||
45 | $modelPk = $entityClass::getEntity()->getPrimary(); |
||
46 | $id = isset($this->data[$modelPk]) ? $this->data[$modelPk] : false; |
||
47 | $bxCode = $this->code . '_' . $className; |
||
48 | $bxCodeType = $codeType . '_' . $className; |
||
49 | |||
50 | if ($this->forceMultiple) { |
||
51 | if ($id) { |
||
52 | $bxCode .= '_' . $id; |
||
53 | $bxCodeType .= '_' . $id; |
||
54 | } else { |
||
55 | $bxCode .= '_new_'; |
||
56 | $bxCodeType .= '_new_'; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | // TODO Избавиться от данного костыля |
||
61 | if ($_REQUEST[$bxCode]) { |
||
62 | $this->data[$this->code] = $_REQUEST[$bxCode]; |
||
63 | } |
||
64 | |||
65 | $editorToolbarSets = array( |
||
66 | 'FULL' => array( |
||
67 | 'Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', |
||
68 | 'CreateLink', 'DeleteLink', 'Image', 'Video', |
||
69 | 'BackColor', 'ForeColor', |
||
70 | 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull', |
||
71 | 'InsertOrderedList', 'InsertUnorderedList', 'Outdent', 'Indent', |
||
72 | 'StyleList', 'HeaderList', |
||
73 | 'FontList', 'FontSizeList' |
||
74 | ), |
||
75 | 'SIMPLE' => array( |
||
76 | 'Bold', 'Italic', 'Underline', 'Strike', 'RemoveFormat', |
||
77 | 'CreateLink', 'DeleteLink', |
||
78 | 'Video', |
||
79 | 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyFull', |
||
80 | 'InsertOrderedList', 'InsertUnorderedList', 'Outdent', 'Indent', |
||
81 | 'FontList', 'FontSizeList', |
||
82 | ) |
||
83 | ); |
||
84 | |||
85 | if ($this->getSettings('LIGHT_EDITOR_MODE') == 'Y') { |
||
86 | // Облегченная версия редактора |
||
87 | global $APPLICATION; |
||
88 | |||
89 | $editorToolbarConfig = $this->getSettings('EDITOR_TOOLBAR_CONFIG'); |
||
90 | |||
91 | if (!is_array($editorToolbarConfig)) { |
||
92 | $editorToolbarSet = $this->getSettings('EDITOR_TOOLBAR_CONFIG_SET'); |
||
93 | if (isset($editorToolbarSets[$editorToolbarSet])) { |
||
94 | $editorToolbarConfig = $editorToolbarSets[$editorToolbarSet]; |
||
95 | } else { |
||
96 | $editorToolbarConfig = $editorToolbarSets['FULL']; |
||
97 | } |
||
98 | } |
||
99 | |||
100 | $APPLICATION->IncludeComponent('bitrix:fileman.light_editor', '', array( |
||
101 | 'CONTENT' => $this->data[$this->code], |
||
102 | 'INPUT_NAME' => $bxCode, |
||
103 | 'INPUT_ID' => $bxCode, |
||
104 | 'WIDTH' => $this->getSettings('WIDTH'), |
||
105 | 'HEIGHT' => $this->getSettings('HEIGHT'), |
||
106 | 'RESIZABLE' => 'N', |
||
107 | 'AUTO_RESIZE' => 'N', |
||
108 | 'VIDEO_ALLOW_VIDEO' => 'Y', |
||
109 | 'VIDEO_MAX_WIDTH' => $this->getSettings('WIDTH'), |
||
110 | 'VIDEO_MAX_HEIGHT' => $this->getSettings('HEIGHT'), |
||
111 | 'VIDEO_BUFFER' => '20', |
||
112 | 'VIDEO_LOGO' => '', |
||
113 | 'VIDEO_WMODE' => 'transparent', |
||
114 | 'VIDEO_WINDOWLESS' => 'Y', |
||
115 | 'VIDEO_SKIN' => '/bitrix/components/bitrix/player/mediaplayer/skins/bitrix.swf', |
||
116 | 'USE_FILE_DIALOGS' => 'Y', |
||
117 | 'ID' => 'LIGHT_EDITOR_' . $bxCode, |
||
118 | 'JS_OBJ_NAME' => $bxCode, |
||
119 | 'TOOLBAR_CONFIG' => $editorToolbarConfig |
||
120 | ) |
||
121 | ); |
||
122 | } else { |
||
123 | // Полная версия редактора |
||
124 | \CFileMan::AddHTMLEditorFrame( |
||
125 | $bxCode, |
||
126 | $this->data[$this->code], |
||
127 | $bxCodeType, |
||
128 | $this->data[$codeType], |
||
129 | array( |
||
130 | 'width' => $this->getSettings('WIDTH'), |
||
131 | 'height' => $this->getSettings('HEIGHT'), |
||
132 | ) |
||
133 | ); |
||
134 | |||
135 | $defaultEditors = array( |
||
136 | static::CONTENT_TYPE_TEXT => static::CONTENT_TYPE_TEXT, |
||
137 | static::CONTENT_TYPE_HTML => static::CONTENT_TYPE_HTML, |
||
138 | 'editor' => 'editor' |
||
139 | ); |
||
140 | $editors = $this->getSettings('EDITORS'); |
||
141 | $defaultEditor = strtolower($this->getSettings('DEFAULT_EDITOR')); |
||
142 | $contentType = $this->getContentType(); |
||
143 | $defaultEditor = isset($contentType) && $contentType == static::CONTENT_TYPE_TEXT ? static::CONTENT_TYPE_TEXT : $defaultEditor; |
||
144 | $defaultEditor = isset($contentType) && $contentType == static::CONTENT_TYPE_HTML ? "editor" : $defaultEditor; |
||
145 | |||
146 | if (count($editors) > 1) { |
||
147 | foreach ($editors as &$editor) { |
||
148 | $editor = strtolower($editor); |
||
149 | if (isset($defaultEditors[$editor])) { |
||
150 | unset($defaultEditors[$editor]); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | |||
155 | $script = '<script type="text/javascript">'; |
||
156 | $script .= '$(document).ready(function() {'; |
||
157 | |||
158 | foreach ($defaultEditors as $editor) { |
||
159 | $script .= '$("#bxed_' . $bxCode . '_' . $editor . '").parent().hide();'; |
||
160 | } |
||
161 | |||
162 | $script .= '$("#bxed_' . $bxCode . '_' . $defaultEditor . '").click();'; |
||
163 | $script .= 'setTimeout(function() {$("#bxed_' . $bxCode . '_' . $defaultEditor . '").click(); }, 500);'; |
||
164 | $script .= "});"; |
||
165 | $script .= '</script>'; |
||
166 | |||
167 | echo $script; |
||
168 | } |
||
169 | $html = ob_get_clean(); |
||
170 | |||
171 | return $html; |
||
172 | } else { |
||
173 | return parent::getEditHtml(); |
||
174 | } |
||
175 | } |
||
176 | |||
296 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: