Conditions | 13 |
Paths | 33 |
Total Lines | 55 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
69 | public static function firstChar( |
||
70 | array $data, |
||
71 | DocumentParser $modx, |
||
72 | DocLister $_DocLister, |
||
73 | prepare_DL_Extender $_extDocLister |
||
74 | ) { |
||
75 | $char = mb_substr($data['pagetitle'], 0, 1, 'UTF-8'); |
||
76 | $oldChar = $_extDocLister->getStore('char'); |
||
77 | if ($oldChar !== $char) { |
||
78 | $sanitarInIDs = $_DocLister->sanitarIn($_DocLister->getIDs()); |
||
79 | $where = sqlHelper::trimLogicalOp($_DocLister->getCFGDef('addWhereList', '')); |
||
80 | $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . $_DocLister->filtersWhere()); |
||
81 | $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . "SUBSTRING(c.pagetitle,1,1) = '" . $modx->db->escape($char) . "'"); |
||
82 | |||
83 | if ($_DocLister->getCFGDef('idType', 'parents') == 'parents') { |
||
84 | |||
85 | if ($where != '') { |
||
86 | $where .= " AND "; |
||
87 | } |
||
88 | $where = "WHERE {$where} c.parent IN (" . $sanitarInIDs . ")"; |
||
89 | if (!$_DocLister->getCFGDef('showNoPublish', 0)) { |
||
90 | $where .= " AND c.deleted=0 AND c.published=1"; |
||
91 | } |
||
92 | } else { |
||
93 | if ($sanitarInIDs != "''") { |
||
94 | $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND"; |
||
95 | } |
||
96 | $where = sqlHelper::trimLogicalOp($where); |
||
97 | if ($_DocLister->getCFGDef('showNoPublish', 0)) { |
||
98 | if ($where != '') { |
||
99 | $where = "WHERE {$where}"; |
||
100 | } |
||
101 | } else { |
||
102 | if ($where != '') { |
||
103 | $where = "WHERE {$where} AND "; |
||
104 | } else { |
||
105 | $where = "WHERE {$where} "; |
||
106 | } |
||
107 | $where .= "c.deleted=0 AND c.published=1"; |
||
108 | } |
||
109 | } |
||
110 | $q = $_DocLister->dbQuery("SELECT count(c.id) as total FROM " . $_DocLister->getTable('site_content', |
||
111 | 'c') . " " . $where); |
||
112 | $total = $modx->db->getValue($q); |
||
113 | $data['OnNewChar'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplOnNewChar'), |
||
114 | compact("char", "total")); |
||
115 | $_extDocLister->setStore('char', $char); |
||
116 | |||
117 | if ($oldChar !== null) { |
||
118 | $data['CharSeparator'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplCharSeparator'), |
||
119 | compact("char", "total")); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | return $data; |
||
124 | } |
||
127 |