Conditions | 12 |
Paths | 12 |
Total Lines | 106 |
Code Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
38 | public function preparePage() |
||
39 | { |
||
40 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
||
41 | $this->P->cb_pagetype = 'content'; |
||
42 | $this->P->cb_subnav = 'admin'; |
||
43 | |||
44 | $this->P->cb_customcontenttemplate = 'textcatadmin'; |
||
45 | |||
46 | $return = ''; |
||
47 | |||
48 | $getaction = filter_input(INPUT_GET, 'action'); |
||
49 | if (empty($getaction)) { |
||
50 | $aData = $this->textcats->getCompleteTextcatForCurrentLang(); |
||
51 | |||
52 | $aListSetting = [ |
||
53 | ['title' => HardcodedText::get('textcatadmin_list_title_key'), 'key' => 'tc_key', 'width' => '20%', 'linked' => false,], |
||
54 | ['title' => HardcodedText::get('textcatadmin_list_title_text'), 'key' => 'tcl_text', 'width' => '80%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
||
55 | [ |
||
56 | 'title' => HardcodedText::get('textcatadmin_list_title_edit'), |
||
57 | 'key' => 'tc_id', |
||
58 | 'width' => 35, |
||
59 | 'linked' => true, |
||
60 | 'ltarget' => '/_admin/textcatadmin.html', |
||
61 | 'lkeyname' => 'id', |
||
62 | 'lgetvars' => [ |
||
63 | 'action' => 'edit', |
||
64 | ], |
||
65 | ], |
||
66 | ]; |
||
67 | $return .= Tools::makeListtable($aListSetting, $aData, $this->serviceManager->get('twig')); |
||
68 | } elseif ($getaction === 'edit' || $getaction === 'delete') { |
||
69 | $getid = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
||
70 | if ($getaction === 'delete' && filter_input(INPUT_POST, 'delete') === 'do') { |
||
71 | $this->textcats->deleteText($getid); |
||
72 | $this->P->cb_customdata['deleted'] = true; |
||
73 | } else { |
||
74 | $this->P->cb_customdata['edit'] = true; |
||
75 | |||
76 | $this->textcats->initTextIfVoid($getid); |
||
77 | |||
78 | // if post:edit is set, update |
||
79 | if (filter_input(INPUT_POST, 'edit') === 'do') { |
||
80 | $this->textcats->purifier = false; |
||
81 | if (HelperConfig::$core['textcat_enable_purifier']) { |
||
82 | $this->textcats->purifier = \HaaseIT\HCSF\Helper::getPurifier('textcat'); |
||
83 | } |
||
84 | $this->textcats->saveText( |
||
85 | filter_input(INPUT_POST, 'lid', FILTER_SANITIZE_NUMBER_INT), |
||
86 | filter_input(INPUT_POST, 'text') |
||
87 | ); |
||
88 | $this->P->cb_customdata['updated'] = true; |
||
89 | } |
||
90 | |||
91 | $aData = $this->textcats->getSingleTextByID($getid); |
||
92 | $this->P->cb_customdata['editform'] = [ |
||
93 | 'id' => $aData['tc_id'], |
||
94 | 'lid' => $aData['tcl_id'], |
||
95 | 'key' => $aData['tc_key'], |
||
96 | 'lang' => $aData['tcl_lang'], |
||
97 | 'text' => $aData['tcl_text'], |
||
98 | ]; |
||
99 | |||
100 | // show archived versions of this textcat |
||
101 | $dbal = $this->serviceManager->get('dbal'); |
||
102 | |||
103 | /** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */ |
||
104 | $queryBuilder = $dbal->createQueryBuilder(); |
||
105 | $queryBuilder |
||
106 | ->select('*') |
||
107 | ->from('textcat_lang_archive') |
||
108 | ->where('tcl_id = ?') |
||
109 | ->andWhere('tcl_lang = ?') |
||
110 | ->setParameter(0, $aData['tcl_id']) |
||
111 | ->setParameter(1, HelperConfig::$lang) |
||
112 | ->orderBy('tcla_timestamp', 'DESC') |
||
113 | ; |
||
114 | $statement = $queryBuilder->execute(); |
||
115 | $iArchivedRows = $statement->rowCount(); |
||
116 | |||
117 | if ($iArchivedRows > 0) { |
||
118 | $aListSetting = [ |
||
119 | ['title' => 'tcla_timestamp', 'key' => 'tcla_timestamp', 'width' => '15%', 'linked' => false,], |
||
120 | ['title' => 'tcl_text', 'key' => 'tcl_text', 'width' => '85%', 'linked' => false, 'escapehtmlspecialchars' => true,], |
||
121 | ]; |
||
122 | $aData = $statement->fetchAll(); |
||
123 | $this->P->cb_customdata['archived_list'] = Tools::makeListtable($aListSetting, |
||
124 | $aData, $this->serviceManager->get('twig')); |
||
125 | } |
||
126 | } |
||
127 | } elseif ($getaction === 'add') { |
||
128 | $this->P->cb_customdata['add'] = true; |
||
129 | if (filter_input(INPUT_POST, 'add') === 'do') { |
||
130 | $postkey = filter_input(INPUT_POST, 'key', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
131 | $this->P->cb_customdata['err'] = $this->textcats->verifyAddTextKey($postkey); |
||
132 | |||
133 | if (count($this->P->cb_customdata['err']) == 0) { |
||
134 | $this->P->cb_customdata['addform'] = [ |
||
135 | 'key' => $postkey, |
||
136 | 'id' => $this->textcats->addTextKey($postkey), |
||
137 | ]; |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $this->P->oPayload->cl_html = $return; |
||
143 | } |
||
144 | } |
||
145 |