Conditions | 12 |
Paths | 12 |
Total Lines | 41 |
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 |
||
46 | protected static function getTreeList(int $id, int $depth, int $begin = 0, string $permClause = ''): string |
||
47 | { |
||
48 | if ($id < 0) { |
||
49 | $id = (int)abs($id); |
||
50 | } |
||
51 | |||
52 | if ($begin === 0) { |
||
53 | $theList = $id; |
||
54 | } else { |
||
55 | $theList = ''; |
||
56 | } |
||
57 | |||
58 | if ($id && $depth > 0) { |
||
59 | $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); |
||
60 | $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); |
||
61 | $queryBuilder->select('uid') |
||
62 | ->from('pages') |
||
63 | ->where( |
||
64 | $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($id, Connection::PARAM_INT)), |
||
65 | $queryBuilder->expr()->eq('sys_language_uid', 0) |
||
66 | ) |
||
67 | ->orderBy('uid'); |
||
68 | if ($permClause !== '') { |
||
69 | $queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($permClause)); |
||
70 | } |
||
71 | $statement = $queryBuilder->executeQuery(); |
||
72 | while ($row = $statement->fetchAssociative()) { |
||
73 | if ($begin <= 0) { |
||
74 | $theList .= ',' . $row['uid']; |
||
75 | } |
||
76 | if ($depth > 1) { |
||
77 | $theSubList = self::getTreeList((int)$row['uid'], $depth - 1, $begin - 1, $permClause); |
||
78 | if (!empty($theList) && !empty($theSubList) && ($theSubList[0] !== ',')) { |
||
79 | $theList .= ','; |
||
80 | } |
||
81 | $theList .= $theSubList; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return (string)$theList; |
||
87 | } |
||
89 |