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($limit, $offset) |
||
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 | 'eco.name', |
||
98 | 'ecot.main_node_id', |
||
99 | 'ecc.serialized_name_list', |
||
100 | 'ecc.identifier AS class_identifier' |
||
101 | ) |
||
102 | ->from($this->connection->quoteIdentifier('ezcontentobject'), 'eco') |
||
103 | ->leftJoin( |
||
104 | 'eco', |
||
105 | $this->connection->quoteIdentifier('ezcontentobject_tree'), |
||
106 | 'ecot', |
||
107 | $query->expr()->eq( |
||
108 | $this->connection->quoteIdentifier('eco.id'), |
||
109 | $this->connection->quoteIdentifier('ecot.contentobject_id') |
||
110 | ) |
||
111 | ) |
||
112 | ->innerJoin( |
||
113 | 'eco', |
||
114 | $this->connection->quoteIdentifier('ezcontentclass'), |
||
115 | 'ecc', |
||
116 | $query->expr()->eq( |
||
117 | $this->connection->quoteIdentifier('eco.contentclass_id'), |
||
118 | $this->connection->quoteIdentifier('ecc.id') |
||
119 | ) |
||
120 | ) |
||
121 | ->where( |
||
122 | $query->expr()->eq('ecc.version', 0) |
||
123 | ) |
||
124 | ->andWhere($query->expr()->in('eco.id', $contents)) |
||
125 | ->groupBy($this->connection->quoteIdentifier('ecot.main_node_id')) |
||
126 | ->setFirstResult($offset) |
||
127 | ->setMaxResults($limit); |
||
128 | |||
129 | $statement = $query->execute(); |
||
130 | |||
131 | return $statement->fetchAll(PDO::FETCH_ASSOC); |
||
132 | } |
||
133 | } |
||
134 |