| Conditions | 3 |
| Paths | 4 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 75 | public function getObjectsWithCollections(int $limit, int $offset): array |
||
| 76 | { |
||
| 77 | $contentIdsQuery = $this->connection->createQueryBuilder(); |
||
| 78 | $contentIdsQuery |
||
| 79 | ->select('DISTINCT contentobject_id AS id') |
||
| 80 | ->from($this->connection->quoteIdentifier('ezinfocollection')); |
||
| 81 | |||
| 82 | $statement = $contentIdsQuery->execute(); |
||
| 83 | |||
| 84 | $contents = []; |
||
| 85 | foreach ($statement->fetchAll() as $content) { |
||
| 86 | $contents[] = (int) $content['id']; |
||
| 87 | } |
||
| 88 | |||
| 89 | if (empty($contents)) { |
||
| 90 | return []; |
||
| 91 | } |
||
| 92 | |||
| 93 | $query = $this->connection->createQueryBuilder(); |
||
| 94 | $query |
||
| 95 | ->select( |
||
| 96 | 'eco.id AS content_id', |
||
| 97 | 'ecot.main_node_id' |
||
| 98 | ) |
||
| 99 | ->from($this->connection->quoteIdentifier('ezcontentobject'), 'eco') |
||
| 100 | ->leftJoin( |
||
| 101 | 'eco', |
||
| 102 | $this->connection->quoteIdentifier('ezcontentobject_tree'), |
||
| 103 | 'ecot', |
||
| 104 | $query->expr()->eq( |
||
| 105 | $this->connection->quoteIdentifier('eco.id'), |
||
| 106 | $this->connection->quoteIdentifier('ecot.contentobject_id') |
||
| 107 | ) |
||
| 108 | ) |
||
| 109 | ->innerJoin( |
||
| 110 | 'eco', |
||
| 111 | $this->connection->quoteIdentifier('ezcontentclass'), |
||
| 112 | 'ecc', |
||
| 113 | $query->expr()->eq( |
||
| 114 | $this->connection->quoteIdentifier('eco.contentclass_id'), |
||
| 115 | $this->connection->quoteIdentifier('ecc.id') |
||
| 116 | ) |
||
| 117 | ) |
||
| 118 | ->where( |
||
| 119 | $query->expr()->eq('ecc.version', 0) |
||
| 120 | ) |
||
| 121 | ->andWhere($query->expr()->in('eco.id', $contents)) |
||
| 122 | ->groupBy([ |
||
| 123 | $this->connection->quoteIdentifier('ecot.main_node_id'), |
||
| 124 | $this->connection->quoteIdentifier('content_id'), |
||
| 125 | ]) |
||
| 126 | ->setFirstResult($offset) |
||
| 127 | ->setMaxResults($limit); |
||
| 128 | |||
| 129 | $statement = $query->execute(); |
||
| 130 | |||
| 131 | return $statement->fetchAll(PDO::FETCH_ASSOC); |
||
| 132 | } |
||
| 133 | } |
||
| 134 |