| Conditions | 12 |
| Paths | 12 |
| Total Lines | 38 |
| Code Lines | 27 |
| 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 |
||
| 58 | protected static function getTreeList(int $id, int $depth, int $begin = 0, $permClause = '') |
||
| 59 | { |
||
| 60 | if ($id < 0) { |
||
| 61 | $id = abs($id); |
||
| 62 | } |
||
| 63 | if ($begin === 0) { |
||
| 64 | $theList = $id; |
||
| 65 | } else { |
||
| 66 | $theList = ''; |
||
| 67 | } |
||
| 68 | if ($id && $depth > 0) { |
||
| 69 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); |
||
| 70 | $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); |
||
| 71 | $queryBuilder->select('uid') |
||
| 72 | ->from('pages') |
||
| 73 | ->where( |
||
| 74 | $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)), |
||
| 75 | $queryBuilder->expr()->eq('sys_language_uid', 0) |
||
| 76 | ) |
||
| 77 | ->orderBy('uid'); |
||
| 78 | if ($permClause !== '') { |
||
| 79 | $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($permClause)); |
||
| 80 | } |
||
| 81 | $statement = $queryBuilder->execute(); |
||
| 82 | while ($row = $statement->fetch()) { |
||
| 83 | if ($begin <= 0) { |
||
| 84 | $theList .= ',' . $row['uid']; |
||
| 85 | } |
||
| 86 | if ($depth > 1) { |
||
| 87 | $theSubList = self::getTreeList((int)$row['uid'], $depth - 1, $begin - 1, $permClause); |
||
| 88 | if (!empty($theList) && !empty($theSubList) && ($theSubList[0] !== ',')) { |
||
| 89 | $theList .= ','; |
||
| 90 | } |
||
| 91 | $theList .= $theSubList; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | return $theList; |
||
| 96 | } |
||
| 98 |